Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.
-
Simple
- Human readable automation
- No special coding skills needed
- Tasks executed in order
- Get productive quickly
-
Powerful
- App deployment
- Configuration management
- Workflow orchestration
- Orchestrate the app lifecycle
-
Agentless
- Agentless architecture
- Uses OpenSSH and WinRM
- No agents to exploit or update
- Predictable, reliable and secure
- Human readable automation
- No special coding skills needed
- Tasks executed in order
- Get productive quickly
- App deployment
- Configuration management
- Workflow orchestration
- Orchestrate the app lifecycle
- Agentless architecture
- Uses OpenSSH and WinRM
- No agents to exploit or update
- Predictable, reliable and secure
https://docs.ansible.com/
- Docker is a open source platform for building, deploying and managing containerized applications. It enables developer to package applications into containers.
- Containers are the executable components that combines the application source code with the Operating System(OS) libraries and dependencies required to run the code in any environment.
- Docker makes it easier, simpler and safer to build, deploy and manage containers
https://docs.docker.com/
- The Apache HTTP Server, colloquially called Apache, is a free and open-source cross-platform web server software, released under the terms of Apache License 2.0.
- Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.
- The vast majority of Apache HTTP Server instances run on a Linux distribution, but current versions also run on Microsoft Windows, OpenVMS and a wide variety of Unix-like systems.
For Apache HTTPD Documentation, visit the link mentioned below:
https://httpd.apache.org/docs/
Let's understand this implementation part by part
Let's understand it task by task:- "Mount Directory Creation" : Creation of Mount Directory
- "Mount Directory to CDROM" : Mount the directory created in previous task to the CDROM
- "YUM Repository - AppStream" : Addition of AppStream YUM repository
- "YUM Repository - BaseOS" : Addition of BaseOS YUM repository
- "Docker Repository Setup" : Creation of repository for Docker tor its installation
- "Setting pip installer" : Setting up pip installer to install Docker SDK for Python
- "Setting SELinux Permissive" : Disabling SELinux for successful creation of Docker container
- "Check whether Docker is installed or not" : Checks for presence of Docker by using the command "rpm -q docker-ce" and is used to make Docker Installation idempotent
- "Docker Installation" : Installs Docker only when the above task satisfies the when condition
- "Starting Docker Service" : Starts Docker service
- "Stopping Firewall Service" : Disabling Firewall for accessing web page from the browser present outside the VM(Virtual Machine)
- "Installation of Docker SDK for Python for using Docker modules in Ansible" : Installation of Docker SDK for Python i.e., "docker-py' for using Docker modules in Ansible
- "Creation of directory" : Creation of directory to be mounted with the HTTPD's document root within Docker container
- "Copying the web page to the directory created" : Web page present within web directory(more details below) is copied to the directory created in previous tasks
- "Restarting Docker Service" : Docker Service is restarted to resolve the error mentioned below
- "Creation of Docker container for httpd" : Involves creation of Docker container using httpd image, the directory created in previous tasks is mounted to the Document Root of httpd and PAT(Port Address Translation) is performed to expose the container created
- name: Mount Directory Creation
file:
state: directory
path: "{{ mount_directory }}"
- name: Mount Directory to CDROM
mount:
src: "/dev/cdrom"
path: "{{ mount_directory }}"
state: mounted
fstype: "iso9660"
- name: YUM Repository - AppStream
yum_repository:
baseurl: "{{ mount_directory }}/AppStream"
name: "DVD1"
description: "YUM Repository - AppStream"
enabled: true
gpgcheck: no
- name: YUM Repository - BaseOS
yum_repository:
baseurl: "{{ mount_directory }}/BaseOS"
name: "DVD2"
description: "YUM Repository - BaseOS"
enabled: true
gpgcheck: no
- name: Docker Repository Setup
yum_repository:
baseurl: https://download.docker.com/linux/centos/7/x86_64/stable/
name: "docker"
description: "Docker repo"
enabled: true
gpgcheck: no
- name: Setting pip installer
package:
name: "python36"
state: present
- name: Setting SELinux Permissive
selinux:
policy: targeted
state: permissive
- name: Check whether Docker is installed or not
command: "rpm -q docker-ce"
register: docker_check
ignore_errors: yes
- name: Docker Installation
command: "yum install docker-ce --nobest -y"
when: '"is not installed" in docker_check.stdout'
- name: Starting Docker Service
systemd:
name: "docker"
state: started
- name: Stopping Firewall Service
systemd:
name: "firewalld"
state: stopped
- name: Installation of Docker SDK for Python for using Docker modules in Ansible
pip:
name: "docker-py"
- name: Creation of directory
file:
path: /root/web_page/
state: directory
- name: Copying the web page to the directory created
copy:
src: web/index.html
dest: /root/web_page/
- name: Restarting Docker Service
systemd:
name: "docker"
state: restarted
- name: Creation of Docker container for httpd
docker_container:
name: httpd_container
image: httpd
pull: yes
detach: yes
state: started
ports:
- "{{ port_number }}:80"
volumes:
- /root/web_page/:/usr/local/apache2/htdocs/
mount_directory: "/dvd1"
port_number: "82"
Used to make Playbook more dynamic and it specifies the value of Port Number(for PAT) and Mount Directory
Hello, it's working
It specifies the web page to be accessed from outside the container
https://www.linkedin.com/in/satyam-singh-95a266182