ARTH — Task 10
>> 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 and expose it to the public
Copy the html code in /var/www/html directory and start the web server
Step 1
CONFIGURING ANSIBLE IN CONTROL NODE
Download Ansible
cmd: pip3 install ansible
Step 2 Create Inventory
Create one inventory file and add ip of managed nodes
for that we need to create a file:-
write the file with respective ip and username and password
Step 3 Create ansible conf file and append the inventory file
- create one dir:- mkdir /etc/ansible
- create a conf file:- vim /etc/ansible/ansible.cfg
- add inventory to conf file
- To check :- ansible all — list-hosts
Step 4 To connect host:-
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
then install sshpass:- yum install sshpass
To check: ansible all -m ping
Initial Setup is completed
Now we have to write the playbook
- create a directory: cmd: mkdir /<name> [eg., mkdir /ws]
- cd /ws ->create a file : vim <file name>.yml [eg., vim web.yml]
and write the playbook :-
code finished play and playbook
cmd:- ansible-playbook <file name>
Now total setup is completed
for checking goto managed node , and check docker is running or not
cmd:-systemctl status docker
Check whether httpd server image has launched
cmd :-docker images
To check the webserver is running or not
Configured docker with httpd using ansible and exposed to public
Thanks for reading🙏