Configure docker and launch container using ansible
In this post, i have created automation using ansible . I have created playbook for configure docker engine and launch new container.
Ansible: Ansible is an open source software , which is used in automation . Ansible is used in provisioning , configuration management , Application deployment , continuous delivery, security automation, orchestration.
In ansible two methods can be used to complete any in target node.
- Ad-hoc and 2. Playbook
Ad-hoc is nothing but command which is used to do job according to user .
Ansible supports YAML language , YAML language is used to create playbook for automation.
For install ansible use below command:
#In Linux OS
pip3 install ansible
Ansible is an agentless software , in ansible controller node manage target node using SSH protocol . For this first of it is necessary to decide manage node in controller node . For configure target node inventory file is created .
For configure ansible edit file “/etc/ansible/ansible.cfg”
In this file it have to mention the inventory file and edit this file according to below
host_key_checking = false
Edit inventory file as below
After doing all setup create playbook for configure docker
- hosts: mywebtasks:
- command: "ls -l /dvd"
when: x.rc != 0 - mount:
fstype: "iso9660" - yum_repository:
description: "docker repo for package"
gpgcheck: no - command: "rpm -q docker-ce"
ignore_errors: yes - command: "yum install docker-ce --nobest -y"
when: y.rc != 0 - command: "systemctl status docker"
ignore_errors: yes - command: "systemctl start docker"
when: docker_status.rc != 0
- command: "systemctl enable docker"
when: docker_status.rc != 0 - pip:
register: c - template:
After creating playbook run below cmd to do all tasks in target
when playbook is run then task is done on those target node which is power on and there is connection setup between controller node and target node.