Using Ansible Launching a docker container , auto updating ip of container to inventory then configuring httpd server on the container
Vivek Sharma
RedHat Certified in Containers and Kubernetes(EX180) ||Arth || Aspiring DevOps Engineer || Python || Docker || Ansible || Jenkins || Kubernetes || OpenShift || Terraform || GitHub || AWS || AZURE
Task Description
?? 14.2 Further in ARTH - Task 10 have to create an Ansible playbook that will retrieve newContainer IP and update the inventory. So that further Configuration of Webserver could be done inside that Container.
This is a continuation of Task 10 given by Arth The School of Technologies.
Here are the steps to accomplish given task -
Steps to be done in localhost
- make a repository for installing docker-ce software .
- Disable Selinux as it can conflict with docker containers .
- Install docker-ce software using yum or dnf and also give --nobest option for installing a compatible version of docker on the system. for this we have to use command module as yum module of ansible do not have --nobest option.
- start and enable docker service .
- Install python3.6 . for interacting with docker ansible uses a python library docker or docker-py to install this library we need pip3 command with will be provided by python3.6 .
- Install docker library using pip3 .
- launch a docker container by using image sshd:v2 ( This image is created by me it has enable sshd service in it .)
- Retrieving all the information of container launched in the variable result .
- printing the ip of the container
- updating the ip of container in the inventory folder
- changing root password of the container so that Ansible can login through ssh .
Steps to be performed in the container-
- installing httpd software
- starting httpd service
- copying the content to /var/www/html/index.html
My Workspace
My playbook (docker22.yml)
Template file to update ip in inventory (con_ip)
File to upload to container (index.html )
Running Playbook
# ansible-playbook docker22.yml
The container is launched we can view it by using command
# docker ps
IP of the container launched is updated in the inventory folder
Httpd server is configured over the container and file is copied . To confirm we can use curl command or the browser
THANK YOU FOR READING.......