How to Integrate Ansible with Docker On AWS Instance..

How to Integrate Ansible with Docker On AWS Instance..

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.

No alt text provided for this image
No alt text provided for this image

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

No alt text provided for this image

Its created successfully now check on managed node.

1) Check docker status.

No alt text provided for this image

2) check docker ps output

No alt text provided for this image

3) now check the Private IP of managed node and try to access.

No alt text provided for this image

Finally, Integrated Ansible with Docker to Configure webserver

Github link : --> https://github.com/apurvwagh/ansible_docker.git

Thank you for reading.

Apurv Waghmare

6k+ & Growing Linkedin Family|| DevOps Specialist at Amdocs || Docker || Kubernetes || 1X AWS || 2X Azure || Ansible || Terraform || Jenkins ||SAFe 6 certified

4 年

Thanks Amit

回复
Amit Sharma

CKA || 1xAWS || 4xGCP || 1xAzure || 2xRedHat Certified || DevOps Engineer [???????]@Searce Inc || Freelancer || Terraform || Ansible || GitLab || Jenkins || Kubernetes || Docker || Openshift || AWS || GCP || Azure

4 年

要查看或添加评论,请登录

Apurv Waghmare的更多文章

社区洞察

其他会员也浏览了