diff --git a/aap/add_vm_to_inventory.yaml b/aap/add_vm_to_inventory.yaml new file mode 100644 index 0000000..e90c0cd --- /dev/null +++ b/aap/add_vm_to_inventory.yaml @@ -0,0 +1,34 @@ +- name: Add host to VM inventory + hosts: localhost + gather_facts: false + vars: + inventory_name: "{{ inventory_name }}" + site_name: "{{ hypervisor | replace('-Baremetal', '') | replace('-', '_') | lower }}" + + tasks: + - name: Add inventory + ansible.controller.inventory: + validate_certs: false + name: "{{ inventory_name }}" + description: "VMs" + organization: "Default" + state: present + + - name: Add host to inventory + ansible.controller.host: + name: "{{ vm_name }}" + description: "" + inventory: "{{ inventory_name }}" + state: present + variables: + ansible_host: "{{ vm_ip }}" + + - name: Add group + ansible.controller.group: + name: "{{ site_name }}_virtualmachine" + description: "Local Host Group" + inventory: "{{ inventory_name }}" + hosts: + - "{{ vm_name }}" + preserve_existing_hosts: true + preserve_existing_children: true \ No newline at end of file