Using Ansible Playbook to configure docker and launch docker container using httpd image
Task Description
Write an Ansible PlayBook that does the following operations in the managed nodes:
🔹 Configure Docker
🔹 Start and enable Docker services
🔹 Pull the httpd server image from the Docker Hub
🔹 Run the docker container
🔹 Start the web server
Prerequisites: python interpreter, Ansible, sshpass should be installed
run ansible — version
If config file = None ,then do the following:
mkdir /etc/ansible
vim /etc/ansible/ansible.cfg , press i to insert contents as below:
Press Esc, then press :wq to save
In inventory give path to your inventory file or create inventory file as below:
Step 1: Configure docker
- Configure yum repository for docker
- By default in yum the value of best is true so we get an error like no best match found and it will not download so we have to set its value to false , when using command line to download we add the nobest option to make value of best to false . By using ansible we can do this by changing the value of best=false in /etc/yum.conf
- Install docker
Step 2: Start and enable docker services
Step 3: Pull the httpd server image from the Docker Hub
- Install docker sdk
- Pull the httpd image
Step 4: Launch docker container using httpd image
Step 5: Start web server
As soon as we launch the container the web server is started
You can find the code at link below:
After running playbook you can check if it is working typing localhost:8080/webpage.html in browser of the managed node
To know more about httpd image refer link below: