Using Ansible-playbook lanuch Docker Container on worker node and run Httpd Container which is linked to local folder where put webpage & this Container is exposed to World and then access Webpage from browser using IP and Port number of worker node.
For this Configuration I take two instance one for Ansible-Master node & Ansible-Target node, I use AWS cloud and EC2 instance is "Amazon Linux".
Ansible ssh configuration (set-up) master and target node must be done and ansible installed.
Ansible-master-target-SSH-Setup-onAWS (Use given link for ssh configuration)
- NOTE:
For this configuration Ansible master node need Docker collection, and also install python3-pip .
Use this command to install Docker community collection:
ansible-galaxy collection install community.docker
On ansible master node i create workspace for this configuration named as "mycode" & create code(webpage) "Index.html" which deploy on apache webserver.
open or write ansible-playbook :
My ansible-playbook name is "myweb.yml" ,
NOTE: Ansible-playbook name must be extension " .yml "
vim myweb.yml
-
download Docker package:
tasks: - name: Install Docker yum: name: docker state: present
-
Start and enable Docker service:
- name: Start Docker service systemd: name: docker state: started enabled: yes
-
Create a file which will add to my apache container create file in path /root/code :
File module in ansible-playbook which help to create directory.
- name: create file for adding container volume file: state: directory path: /root/code1
-
Local code or local Webpage copy:
Copy module in ansible-playbook helps to copy my local master node code to target node dest: /root/code1 this destination is point 3 i have created
- name: copy local code or deploy webpage copy: src: index.html dest: /root/code1
-
Pull httpd image for Docker Container:
- name: Pull httpd image from Docker Hub docker_image: name: httpd source: pull
-
Launch Docker container using httpd image & exposed this httpd container for clients. Here i have atached volume to container this volume contain my webpage "index.html" from master node to Target node to docker httpd container:
- name: Run httpd container docker_container: name: my_httpd_container image: httpd state: started exposed_ports: 80 ports: - "8080:80" volumes: - /root/code1/index.html/:/usr/local/apache2/htdocs/index.html restart_policy: always
ansible-playbook myweb.yml
After ansible-playbook run successfully, on Target node Automation take place & configure our tasks
On google - "< public ip of target node > : port no /index.html"
Also from my laptop command prompt: using "curl" command