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 • 100,998 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:57 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 instill ansible. And we're going to run it in a doctorate container which is going to be pretty cool. So OK if you have never heard about Asiel before don't worry. We're going to be covering every single step here. So let's look for instill ansible pep Linux for example. And remember if you didn't know it ansible is like eight years Klein that we installed before. This is a python library so we can install is using Peppe. So let's click into for its resodding heater and we're going to look for latest leases Peppe. So as you can see this is pretty simple. Only one thing that we need to do is like pip install ansible which is quite simple. OK. No in. We're going to go to our Jenkin's data directory. Remember that at this moment we're outside of the container. So if you take a fluke on your current directories and then you see your centers and darker file remember that we did something similar in here. We're installing Peppe. Well downloading a file then installing Peppe with this command and finally using these new command which is Peppe and install in the package at once. So we can actually use this instruction to instill as evil. OK so we're going to be working with ansible in Jenkyns. So our Jenkin's container is going to need ansible installed. So if we go inside of the Jenkins container ring here and if we type Anzhi Well we don't have ansible install. So we need to install it. So for ideas let's create another directory which is going to be Jenkin's ansible. Let's head to that directory in here. And as you may guess what do we normally use to create an image. I know you know it and there is a darker. 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 an abductor file. We need to start with a from instruction which tells Dharker which image to pick as the vase. So in this case we're going to be used the Jenkins image. Remember we used this image to create our initial container. Ronnie Jenkins. So once we are doing this we are going to occur. Hey Doctor please take this image as a vase. So at this point in this darker file we already have all the four Jenkins image in here. All of that configuration and all the stuff needed for a Jenkin's to run. Now here is the cool point. And if you go let me show you. If you go inside of the Jenkyns container you're going to see that the user in this case is the Jenkin's user which has one in the house and as a nightie. Cool but if you go to the remote host container you're going to see that the user in this case is that rude user. And as you may know the root user has all the super powers to install things on the system but the Jenkin's user probably will not have those superpowers and it's going to complain about permissions. So let's get out of this container out of all of their containers. Actually we're outside in now keeping in mind what I told you. We're going to modify our darker fiber. Remember that currently we're in the Jenkin's as folder that we created. So let's go in modified Ducker files that we've created and let's run that user instruction. And this is something new for us. Any doctor file user instruction means which user it's going to be executing the commands. So in this case once the user route VI execute in all of their commands that we're passing here. So what are we going to do. We're going to look for it. Did Dharker file into Santo's and directory the ducker file that we created to install Amazon's. Lie. So let's copy the line. Let's open our darker file and let's pays that in here. Pretty cool as you can see we have all what we need. We have the Jenkin's emerging here at user rude and now we're downloading the script then Ron and this script and now we need to change this ansible. Pretty cool. So remember that we modified it user as that user route and now we need to lift things as they were before. So lets type user again and let's put that Jenkyns user back so coolly does that profile is actually instructing darker to start from the Jenkin's image change the user to that root user round these commands to avoid permissions problems and then switching back to the Jenkin's user. Pretty cool. So let's go ahead and save face Doctor file. Right and now what we need to do is that we need to modify our current compose file Remember the hour Dharker compose is the file that holds all the definitions for our services. So in this case we're going to do it for things. The first one is that we're going to create a new image which is going to be called Jenkin's as you will 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 these new image using our context and what is that context as in this case the context means the folder where a doc profiles that we create at libs. So let's look for that folder which is Jenkin's ansible and then we're going to see the doc or file there too. So let's copy the name of the folder right. Copy and then we're going to get to that context section that PE is using here and that's it. So we're telling doctor hey doctor please for the Jenkin's service you are no longer going to be used in the Jenkyns slash Jenkins image. Now we're going to use a new image which is going to be built by me and you are going to be all that much use in these folder as the context. It means that the doctor file should be under his folder. So pretty cool. That's safe. That's And remember we need to do a Dockerty composed Beeld which tells darker darker Please read my darker composed file and build all the features and all that configuration that I instructed you. So in this case as you can see our profile is being run. We can see it from instruction here. Would you find it user read here download in the paper as tough an install and as able as well. 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 dock file was correct and now everything is working cool remember that we just need to recreate the Jenkin's container in order to use our new conflagration. So to do this we need to do Duckery compose Dashti which is going to recreate the Jenkin's container using the new image that we created. Please remember to run this command inside of the folder that holds the door Kirt compose file. You should be at the same level of DS file to avoid errors. So this is it. That's ahead in Zad of the Jenkin's container. Let's look for the ansible command and he will 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 it is pretty cool. We already install ansible in docker and in the Jenkin's container. So we cannot run playbooks in here. Cool. This is it for this video. I'll see you in the next lesson.