APACHIE WEBSERVER CONFIGURATION IN DOCKER USING ANSIBLE
Today, let us learn about ansible and using ansible-playbook we have perform some tasks.
🔰 cofigure Docker using ansible.
🔰 Start the services and enable docker .
🔰 pull the httpd server image from the Docker Hub.
🔰 Run the httpd container and expose it to the public .
🔰 copy the Html code in /var/www/html directory and start the web server.
now let start the firstwe have two vm which are already created but not configured yum in the both.
we have to configure both vm of redhat using ansible-playBook.
in other redhat-vm we have configure yum and we install ansible via
pip3 install ansible
we can check the ansible version after installation via a command
ansible - -version
we can createw a group of IP in the /ip.txt, in that we wirte ip of managed nodes as host in controller node. give the usename and password of the managed nodes this is knows inventory which helps us in automation the node which are in the group. you can see that there two ip which are in the group.
before perform the action on the managed node we need to check that all node are connected and pingable or not. That can be checked by following command.thoat managed nodes ip’s are connected with node that only.
Now, we can say that we are connected properly and then we have to configure the ansible.cfg file in the directory /etc/ansible/ . To run the playbook we need to give ssh permissions. this can be done via host_key_checking = False and we should also disable warning command command_warning= False.
Now, we have create our own playbook to run the code. Ansible support a language YAML in the playbook . so we have create the playbook file and as well as the index.html file and the play book file is docker.yml file
code inside the docker.yml is given below in a detailed way.
- hosts: all
tasks:
- name: “ repository”
yum_repository:
name: “Docker”
description: “Docker Repo”
baseurl: “https://download.docker.com/linux/centos/7/x86_64/stable"
gpgcheck: “no”
- name: “Installing Docker package”
command: “yum install docker-ce — nobest -y”
- name: “Starting docker service”
service:
name: “docker”
state: started
enabled: yes
- name: “Installing Docker SDK for python3”
command: “pip3 install docker”
- docker_image:
name: “httpd:latest”
- docker_container:
name: “myhttpd”
state: present
image: httpd:latest
ports: “8081:80”
volumes: /var/www/html:/usr/local/apache2/htdocs/
- copy:
src: “/root/index.html”
dest: “/var/www/html/”
- docker_container:
name: “myhttpd”
state: started
to run the playbook you need to write ansible-playbook docker.yml before running the playbook we can even check the for any syntax errors by
ansible-playbook - -syntax-check docker.yml
After successfully running the playbook, you can check the container whether it is lunched successfully or not.
you can see that we have properly lunched myhttpd container successfully.you can also check the ip of that container.
Now, you can connect this ip and see this web that is index.html. you can see this output WELLCOME TO THE WORLD! which we have writtem in index.html.
Hope you had find this article intersting .
Thank You!😊😊😊😊😊😊😊😊