• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

UnixArena

  • Home
  • kubernetes
  • DevOps
    • Terraform
    • Jenkins
    • Docker
    • Openshift
      • OKD
    • Ansible engine
    • Ansible Tower
      • AWX
    • Puppet
  • Cloud
    • Azure
    • AWS
    • Openstack
    • Docker
  • VMware
    • vCloud Director
    • VMware-Guests
    • Vcenter Appliance 5.5
    • vC OPS
    • VMware SDDC
    • VMware vSphere 5.x
      • vSphere Network
      • vSphere DS
      • vShield Suite
    • VMware vSphere 6.0
    • VSAN
    • VMware Free Tools
  • Backup
    • Vembu BDR
    • Veeam
    • Nakivo
    • Azure Backup
    • Altaro VMBackup
    • Spinbackup
  • Tutorials
    • Openstack Tutorial
    • Openstack Beginner’s Guide
    • VXVM-Training
    • ZFS-Tutorials
    • NetApp cDot
    • LVM
    • Cisco UCS
    • LDOM
    • Oracle VM for x86
  • Linux
    • How to Articles
    • Q&A
    • Networking
    • RHEL7
  • DevOps Instructor-led Training
  • Contact

Jenkins – Ansible – Configure Dynamic Inventory

April 15, 2019 By Cloud_Devops 2 Comments

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
Invoke Ansible Playbook – Inline content

 

4. Enter the desired variable name.

Invoke Ansible Playbook - Inline content
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
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
Inventory – Passing – Jenkins

 

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

Dynamic Inventory passing - Execution
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 !!!

Filed Under: Ansible engine, Configuration Management, DevOps, Jenkins Tagged With: Ansible, Jenkins

Reader Interactions

Comments

  1. Mahesh says

    January 12, 2021 at 1:53 pm

    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}

    Reply
  2. Rajiv CJ says

    January 26, 2020 at 9:20 am

    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

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Follow UnixArena

  • Facebook
  • LinkedIn
  • Twitter

Copyright © 2025 · UnixArena ·

Go to mobile version