How to Integrate Ansible with Docker On AWS Instance..
Apurv Waghmare
6k+ & Growing Linkedin Family|| DevOps Specialist at Amdocs || Docker || Kubernetes || 1X AWS || 2X Azure || Ansible || Terraform || Jenkins ||SAFe 6 certified
Write an Ansible PlayBook that does the following operations in the managed nodes:
- Configure Docker & Install it.
- Start and enable Docker services.
- Pull the httpd server image from the Docker Hub.
- Copy the html code to the directory in the container .
- Run the httpd container and expose it to the public .
Step 1: Install Ansible using pip command ….
# yum install python3
# python3 --version
Python 3.6.8
# pip3 install ansible
Check whether ansible is installed or not using command.
Step 2: Check whether ansible is installed or not using command Now configure the ansible.
Save the IP address of Managed Node in <file.txt> and also give username and password for login purpose … Here is my file …
Ansible always checks for .cfg file … So that we have to create one file called ansible.cfg And in that , we have to write the inventory which we have saved before Here is ansible.cfg file.
Step 3: Now We have to write the playbook to configure webserver on Docker.
write the hosts group and first task (i.e) configuring repo for Docker using yum_repository module. in aws instance yum repo is already created.
- Now Installing docker using package module … Here I am using particular version of Docker which is stable
- Now start and enable the service docker using service module
- To use Ansible Docker module we need to install docker SDK for python3
- Create one html file … And also create a separate directory and copy the html file in the managed node
Step 4: Final step is to run the container using HTTPD image.The image will automatically downloads from hub.docker.com And exposed to public to access the webpage and Mounted the pre-created webpages folder to the /usr/local/apache2/htdocs.
So finally run the below command to run the playbook.
#ansible-playbook docker.yaml
Its created successfully now check on managed node.
1) Check docker status.
2) check docker ps output
3) now check the Private IP of managed node and try to access.
Finally, Integrated Ansible with Docker to Configure webserver
Github link : --> https://github.com/apurvwagh/ansible_docker.git
Thank you for reading.
6k+ & Growing Linkedin Family|| DevOps Specialist at Amdocs || Docker || Kubernetes || 1X AWS || 2X Azure || Ansible || Terraform || Jenkins ||SAFe 6 certified
4 年Thanks Amit
CKA || 1xAWS || 4xGCP || 1xAzure || 2xRedHat Certified || DevOps Engineer [???????]@Searce Inc || Freelancer || Terraform || Ansible || GitLab || Jenkins || Kubernetes || Docker || Openshift || AWS || GCP || Azure
4 年Great Apurv Waghmare