Are you using Jenkins as front-end GUI for Ansible Automation? Have you ever tried the dynamic inventory in Jenkin’s Ansible plugin? Ansible Inventory can be created using the plugin’s dynamic inventory feature. This feature could be very useful when you want to pass hosts as user-defined input and that’s is not part any of the inventory lists. In some of the cases, we will hide the master inventory to prevent accidental playbook execution against those. This could also be useful when you want to run a playbook against newly built servers which might not part of the inventory.
To know more about Ansible Dynamic Inventory, please check it in Ansible Documentation.
1. Login to Jenkins console.
2. Click on the configure Jenkins Job which is associated with Ansible plugin.
3. Select “inline content” from the “Invoke Ansible Playbook” plugin.
4. Enter the desired variable name.
5. Navigate to the general tab to configure “INVENTORY” variable as an input parameter. This is the Multi-line String Parameter tab to accommodate many hosts.
6. Trigger the Jenkins Job. Enter the required variable values. In the Inventory tab, you could copy & paste the host’s list. Note: Playbook has written with “hosts: all ” to accommodate any hosts.
7. Here is the console output of the triggered job.
We have successfully executed the playbook against the host which was not part of any inventories. Inventory has been dynamically created using the user-defined input (Parameterized Build). Hope this article informative to you.
Share it! Comment it!! Be Sociable !!!
Mahesh says
fatal: [{INVENTORY}]: UNREACHABLE! => {“changed”: false, “msg”: “Failed to connect to the host via ssh: ssh: Could not resolve hostname {inventory}: No address associated with hostname\r\n”, “unreachable”: true}
Rajiv CJ says
I am doing something similar, but ran into trouble when trying to pass multiple hosts list as a parameter. Can you help with how to pass multiple hosts as a parameter