Ansible code to update AWX Ansible Inventory
Here is the playbook:
---
- name: Update Inventory
hosts: localhost
gather_facts: False roles:
- role: roles/update_inventory
- name: Update Inventory
hosts: localhost
gather_facts: False roles:
- role: roles/update_inventory
localhost is used for hosts: because the AWX REST API endpoints are accessible from the Ansible master we are running on.
Use that playbook in an AWX Job Template
- The job template needs to prompt the user for "Inventory" on launch.
Respond with the inventory the hosts you wish to update are in. This will provide the value to the special AWX variable tower_inventory_id.
- The job template needs to prompt the user for "Variables" on launch.
Example:---update_ati_fqdns:- host1.example.com- host2.example.comansible_connection: 'local'
- You will need a survey for your Job Template
- Admin Username: admin_username
- Admin User Password: admin_password
- URL for AWX REST API GROUP endpoint: http://awx.example.com/api/v2/groups
- update_ati_group: integer
- Action: pulldown [REMOVE_FROM_GROUP, ADD_TO_GROUP]
Here is the role:
defaults/main.yml
---
awx_base_url: "https://awx.example.com"
tasks/main.yml
---
- name:
ansible.builtin.include_tasks: test_block_loop.yml
loop: "{{ update_ati_fqdns }}"
No comments:
Post a Comment