Site icon UnixArena

Jenkins – Ansible – Configure Dynamic Inventory

Dynamic Inventory - Jenkins

Dynamic Inventory - Jenkins

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.

Invoke Ansible Playbook – Inline content

 

4. Enter the desired variable name.

Invoke Ansible Playbook – Inline content

 

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.

Parameterized – Inventory Passing

 

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.

Inventory – Passing – Jenkins

 

7. Here is the console output of the triggered job.

Dynamic Inventory passing – Execution

 

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 !!!

Exit mobile version