1 minute read

In the new virtual machine provisioning process, vRO creates the machine and registered it to the Satellite host group selected by user. Now AAP will take over to configure the VM. Before the playbooks can run against this new VM, we will need to import it from Satellite into AAP inventory. The regular Satellite inventory sync takes a long time to run because it queries all hosts managed by Satellite. It is not feasible to run Satellite inventory sync to just import one host. We can use host_filters attribute, but the AAP inventory source does not accept variable. So the solution is to run ansible-inventory directly with host_filters for the target VM. Captures the output which includes all Satellite parameters associated with the VM and import them into AAP using the infra.controller_configuration.hosts role to create the host in AAP inventory

# Required Collection
#   infra.controller_configuration
# Rquired Variables
#   controller_*: credential for AAP
#   satellite_*: credential for Satellite
#   target_host: host to be imported
#   controller_inventory: AAP inventory name
- name: Import single host from Satellite 
  hosts: localhost
  connection: local
  gather_facts: false

    controller_hostname: ""
    controller_username: ""
    controller_password: ""
    controller_oauth_token: ""
    controller_validate_certs: ""
    satellite_url: ""
    satellite_user: ""
    satellite_password: ""
    working_dir: /tmp

    - name: Import single host
        - name: Stage Foreman inventory plugin file
            dest: "/my.foreman.yml"
            mode: "0600"
            content: |
              plugin: redhat.satellite.foreman
              url: ""
              user: ""
              password: ""
              validate_certs: no
              want_host_group: yes
              want_params: yes
              want_host_collections: yes
              want_facts: yes
              use_reports_api: yes
              host_filters: 'name='

        - name: Run Foreman inventory plugin
            cmd: "ansible-inventory -i my.foreman.yml --host "
            chdir: ""
          register: _output

        - name: DEBUG
            msg: ""
            verbosity: 1

        - name: Set host parameter variables
            import_host_vars: ""

        - name: DEBUG
            msg: ""
            verbosity: 1

        - name: Add host to AAP inventory
            name: infra.controller_configuration.hosts
              - name: ""
                inventory: ""
                variables: ""
          register: _import_host_output

        - name: Remove Foreman inventory plugin file
            path: "/my.foreman.yml"
            state: absent

Leave a comment