Setting up Docker Configuration By Ansible

Why Ansible?

How to set up Ansible in Controlled Node?

  1. Min 2GB RAM
  2. 64-bit support required (kernel and runtime)
pip3 install ansible
$vi /etc/myhosts.txt[<name>] ansible_ssh_user=<username> ansible_ssh_pass=<password> ansible_ssh_user=<username> ansible_ssh_pass=<password>
$ansible all -m ping
  1. So here we first make a repository of docker by the yum_repository package, here we have to provide the name, description, file, baseurl, gpgcheck for more parameters see the official documentation of ansible. Before it, we have to provide the host.
- hosts: <name>
- name: docker-repo
name: 'docker'
description: 'Docker Repo'
file: 'docker-repo'
baseurl: ""
gpgcheck: no
- name: docker_install
cmd: 'yum install docker-ce --nobest'
register: docker_install_status
- debug:
var: docker_install_status
   - name: docker-service
name: 'docker'
state: started
enabled: yes
register: docker_service_status
- debug:
var: docker_service_status
- name: python for docker
name: 'docker'
- name: pulling_image
name: 'httpd'
source: pull
register: docker_image_status
- debug:
var: docker_image_status
- name: copy-file
src: '/root/ansifol/index.html'
dest: '/root/http/index.html'
register: Copy_file_status
- debug:
var: copy_file_status7
- name: start-container
name: 'httpd'
image: 'httpd'
state: started
detach: yes # run in background
- "8081:80" #linking port 80 to 8081
- /root/http/:/usr/local/apache2/htdocs/:ro
register: container_status
- debug:
var: container_status
$ansible-playbook <name of file>.yml

Thank you!



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store