Hi team
As you know Jenkins has over 1700 plugins available which make him one of the most powerful and flexible tool ever created:) so let’s see one of the most interesting plugin:Making builds with Ansible Plugin.

What is Ansible?

It is a tool to deploy software and application on many servers, it can be really useful in case of update patch or new versions to be added on many machines , with Ansible all that can be done in a row 😀

Note:
You can find on dbi bloggers some interesting topics on Ansible, I invite you to take a look on it!

Install Ansible on your Jenkins Master

[root@localhost ~]# yum install Ansible

[root@localhost ansible]# ansible --version
ansible 2.9.21
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.6/site-packages/ansible
executable location = /usr/bin/ansible
python version = 3.6.8 (default, May 21 2019, 23:51:36) [GCC 8.2.1 20180905 (Red Hat 8.2.1-3)]
[root@localhost ansible]#

Install Ansible plugin on Jenkins

Go to plugin management and search for Ansible

Install plugin and wait for confirmation

Once installed you can see in build environment that you have many Ansible choices

I also invite you to visit jenkins io website especially the Ansible plugin link https://plugins.jenkins.io/ansible/ to have a bunch of info and ways to use it

Configure ssh keys for your hosts

[root@localhost ~]# ssh-keygen -t rsa

Input the parameters you want then once your key is generated  send the public key to the target server

[root@localhost ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@targetserver

Try to connect with ssh to check if connexion is OK

[root@localhost ~]# ssh [email protected]
Activate the web console with: systemctl enable --now cockpit.socket
Last login: Fri Jun 18 17:54:43 2021 from 192.16X.5X.3X
[root@serveurctmv900 ~]#

Configure your build to use Ansible

We will select invoke Ansible playbook
In the build part you can now add the path of your playbook
You can also add many parameters for example specify an inventory

Start your build and check if all i working


We have the same result as command sent on the prompt

Conclusion

That’s it , you know now how to invoke an Ansible playbook using Jenkins, note that you have many ways to do that,this time we saw by using Ansible plugin , but you can also put the playbook command in a pipeline or store your playbooks directly on you git.
Next time we will see how to troubleshoot some issues encountered for this demo and some other tricks on Jenkins  😉 ,stay tuned