https://github.com/pratikshinde55/ansible-configure-webserver_inside-docker_container
Automated Web Server configuration in Docker containers using Ansible, highlighting expertise in playbook development and infrastructure automation.
https://github.com/pratikshinde55/ansible-configure-webserver_inside-docker_container
ansible-galaxy ansible-modules ansible-playbook apache-http-server docker-container
Last synced: 3 months ago
JSON representation
Automated Web Server configuration in Docker containers using Ansible, highlighting expertise in playbook development and infrastructure automation.
- Host: GitHub
- URL: https://github.com/pratikshinde55/ansible-configure-webserver_inside-docker_container
- Owner: Pratikshinde55
- Created: 2024-03-04T13:12:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-25T10:39:40.000Z (8 months ago)
- Last Synced: 2025-01-13T16:50:33.455Z (4 months ago)
- Topics: ansible-galaxy, ansible-modules, ansible-playbook, apache-http-server, docker-container
- Homepage:
- Size: 57.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Configure webserver inside Docker by using Ansible Automation
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".

### prerequisites:
Ansible ssh configuration (set-up) master and target node must be done and ansible installed.
[Ansible-master-target-SSH-Setup-onAWS](https://github.com/Pratikshinde55/Ansible-setup-onAWS.git)
(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
### Here some information about playbook tasks:
1. **download Docker package**:
tasks:- name: Install Docker
yum:
name: docker
state: present
2. **Start and enable Docker service**:- name: Start Docker service
systemd:
name: docker
state: started
enabled: yes3. **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
4. **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/code15. **Pull httpd image for Docker Container**:
- name: Pull httpd image from Docker Hub
docker_image:
name: httpd
source: pull6. **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
### Run ansible playbook :ansible-playbook myweb.yml

**After ansible-playbook run successfully, on Target node Automation take place & configure our tasks**

### Now From Browser i can access my Webserver :
On google - "< public ip of target node > : port no /index.html"

**Also from my laptop command prompt: using "curl" command**
