Install Ansible: Docker + Jenkins

Ricardo Andre Gonzalez Gomez
A free video tutorial from Ricardo Andre Gonzalez Gomez
Linux System Engineer
4.4 instructor rating • 5 courses • 107,470 students

Learn more from the full course

Jenkins, From Zero To Hero: Become a DevOps Jenkins Master

Become a DevOps Master learning Jenkins & integrations with powerful tools like Docker, Ansible, AWS, GIT & more!

10:33:59 of on-demand video • Updated May 2020

  • Learn what is Jenkins and how it works in depth
  • Learn Continuous Integration and Continuous Deployment
  • Learn how to integrate Jenkins with Docker, Ansible, AWS, GIT, Email, Maven and more!
  • Learn how to design and build your own Jobs with a bunch of tools
  • Orchestrate the most popular DevOps tools nowadays
English [Auto] Hello and welcome back. In this video, we're going to learn how to install Ansible and we're going to run it in a darker container, which is going to be pretty cool. So, OK, if you have never heard about Ansible before, don't worry, we're going to be covering every single step in here. So let's look for install Ansible Pappe Linux, for example. And remember, if you didn't know it, Ansible is like the alias client that we installed before. This is a Python library so we can install days using PIP. So let's click into Fritze resulting here and we're going to look for latest releases PEP. So as you can see, this is pretty simple. The only one thing that we need to do is like pip install Ansible, which is quite simple. So, OK, no, in this we're going to go to Red Jenkins' data directory. Remember that at this moment we're outside of the container. So if you take a look on your current directories and then you see your CentOS even Docker file, remember that we did something similar in here. We're installing Pappe well, downloading a file, then installing Peppe with this. Come on. And finally using these Newcomen, which is PIP and installing the package at once so we can actually use this instruction to install as evil. OK, so we're going to be working with Ansible in Jenkins'. So our jenkins' container, it's going to net Ansible installed. So if we go inside of the jenkins' container here and if we type Ansible, we don't have Ansible installed, so we need to install it. So for this, let's create another directory, which is going to be Jenkins' Ansible. Let's head to that directory in here. And as you may guess, what do we normally use to create a new image? I know you know it. And this is a darker file, so let's create a darker file. In this folder to create our new service, so, OK, here we're going to do something cool. Remember that always in adductor file, we need to start with a from instruction which tells Dacher which image to pick as the face. So in this case, we're going to be using the Jenkins' image. Remember that we used this image to create our initial container, Ronnie Jenkins. So once we are doing this, we're telling Doucoure, Hey Doctor, please take this image as a vais. So at this point in this darker file, we already have all the full jenkins' image in here with all of that configuration and all this stuff needed for Jenkins to run now in here. There is a cool point. And if you go, let me show you, if you go inside of the jenkins' container, you're going to see that the user in this case is the jenkins' user, which has 1000 as a Nidhi. Cool. But if you go to that remote post. Container, you are going to see that the user in this case is that user, and as you may know, the user has all the super powers to install things on the system, but the jenkins' user probably will not have those super powers and it's going to complain about permissions. So let's get out of this container, out of all of the containers. Actually, we're outside and now. Keeping in mind what I told you, we're going to modify our biography to remember that currently we're under Jenkins and Will folder that we created. So let's go and modify the Ducker file that we created and let's run the user instruction. And this is something new for us. A. A doctor file user instruction means which user it's going to be executing the commands. So in this case, we want the user ruit to be executing all of the commands that we're going to parsing here. So what are we going to do? We're going to look for deductive file in the Centocelle directory, the Ducker file that we created to install Amazon Zoli. So let's copy this line. Let's open our Docker file and let's pay. Is that in here? Pretty cool, as you can see, we have all what we need, we have the jenkins' imaging here, the user rude, and now we're downloading this script, then running this as crap, and now we need to change this ansible. Pretty cool. So remember that we modified it user as that user routes and now we need to lift things as they were before. So let's type user again and let's put Jenkins' user back. So this doctor, father is actually instructing doctor to start from the jenkins' image, change that user to user round these commands to avoid permissions problems and then switching back to the jenkins' user. Pretty cool. So let's go ahead and save this doctor file. Right. And now what we need to do is that we need to modify our Dr. Campos file. Remember that our Dr. Campos is the file that holds all the definitions for our services. So in this case, we're going to do a few things. The first one is that we're going to create a new image, which is going to be called Jenkins' Ansible, for example. You can name it as you want. And we're going to do something similar to this. So we're going to tell doctor, hey, doctor, please build this new image using a context. And what is that context? As in this case, the context means the folder where the doctor followed up with created lips. So let's look for that folder, which is Jenkins' Ansible, and then you are going to see the doctor foudre. Cool. So let's copy the name of the folder, write copy, and then we're going to go to the context section. That's page using here and that's it. So we're telling doctor, hey doctor, please, for the jenkins' service, you're no longer going to be using the Jenkins' Jenkins image. Now you're going to use a new image, which is going to be built by me. And you are going to build that image using these folder as a context. It means that the Docker file should be under this folder. So pretty cool that save this. And remember, we need to do a to composed Beeld, which tells the doctor, please read my doctor, compose a file and build all the features and all the configuration that I instructed you. So in this case, as you can see, our doctor profile is being run. We can see the from instruction here we find it user RWD here. It's downloading the PIP stuff and installing Ansible as well. So this is pretty cool. We only need to wait until this finishes and this is awesome. As you can see here, the installation, everything completed successfully, which means that our doctor felt was correct and now everything is working cool. Remember that we still need to recreate the jenkins' container in order to use our new configuration. So to do this, we need to do Dr. Campo's Dashti, which is going to recreate the jenkins' container using the new image that we created. Please remember to run this command inside of the folder that holds the doctorate compose file. You should be at the same level of these file to avoid errors. So this is it. Let's go ahead instead of the Jenkins container. And let's look for the tangible command and enter it now, doesn't show any errors, instead is showing you how to use Ansible and which flags or options you have a bailable. So this is pretty cool. We already install Ansible in Docker and in the Jenkins container, so we cannot run playbooks in here. Cool. This is it for this video. I'll see you in the next lesson.