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 😀
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
[[email protected] ~]# yum install Ansible
[[email protected] 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)] [[email protected] ansible]#
Install Ansible plugin on Jenkins
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
[[email protected] ~]# ssh-keygen -t rsa
Input the parameters you want then once your key is generated send the public key to the target server
[[email protected] ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
Try to connect with ssh to check if connexion is OK
[[email protected] ~]# 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 [[email protected] ~]#
Configure your build to use Ansible
Start your build and check if all i working
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