Ansible playbook that will retrieve new Container IP and dynamically update the inventory and Configure web-server inside that Docker Container

Ansible is a popular open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intra-service orchestration and provisioning. It is both light weight and simple to deploy, manage and use. The Ansible platform makes it easy for administrators and developers to automate many tasks, including applying updates to machines on the network to managing devices on the network.

Ansible Platforms
Ansible has three offerings:
• Ansible: A free, open source automation product
• Ansible Tower: An enterprise offering which gives you a graphical interface and enables integration with other services and tools. Tower gives permission control and will also save a record of all Ansible playbook activity, useful for auditing purposes.

Ansible Galaxy: This refers to the Galaxy website where users can share roles, and to a command line tool for installing, creating and managing roles.


You can leverage the capabilities of Ansible in multiple ways:

• Ad-Hoc: Issue ansible tasks direct from the command line. This is a good place to start to understand the basics of what Ansible can do prior to learning the playbooks language — adhoc commands can also be used to do quick things that you might not necessarily want to write a full playbook for.

• Playbooks: These are automation scripts. Playbooks are Ansible’s configuration, deployment, and orchestration language. They can describe a policy you want your remote systems to enforce, or a set of steps in a general IT process.

Automation Framework: Requires the Ansible Tower.

Check Mode: An option for running ad-hoc commands or playbooks without making changes. This deployment guide walks you through working with playbooks.

Key terms

• Playbook: A file used to set configurations and automate any manual processes. These are plain text files written in the Ansible automation language which describe the intended endstate of a deployment or task being executed.

• Ansible automation language: The structure used when writing playbooks and other resources for Ansible. The Ansible automation language uses YAML and is intended to be both human and machine readable.

Plays: Operations within a playbook and execute tasks.

• Tasks: Used within a play to call modules and run in order.

• Roles: A grouping of files and playbooks which makes it easier to organize complex operations.

• Inventory: A list of hosts, or servers, that the control machine can use in its orchestration tasks.

Host: In Ansible, a host is a remote machine that is assigned to individual variables and they are further grouped together. Each host has a dedicated name or unique IP address to make its identification easy and quick. They can be given simple port number too if you don’t have to access them over SSH connection.

Modules: Also referred to as ‘task plugins’ or ‘library plugins’, these control system resources and provide integrations with other services. Modules are the main components that help to install packages, allow APIs to interact together and plan actions for system files too. There are a variety of modules in Ansible that are programmed to automate almost everything inside the tool.

Plug-ins: They are the special pieces of code that help to write code quickly. Plug-ins automate the development tasks and help to speed up the deployment work to the maximum level.

Control machine: Also referred to as a ‘control node’. The system where you run your Ansible playbooks from.

Let’s get into the practicles:

Ansible playbook to install, launch and configure docker

vars_prompt: to prompt the user for certain input

yum_repository : to add or remove YUM repositories in RPM-based Linux distributions.

pip: to manage Python library dependencies

package: Installs, upgrade and removes packages using the underlying OS package manager.

Let’s Started..

In Ansible Playbook:

Now we will Run ansible playbook:

ansible-playbook  docker.yml

We can see that our inventory is updated, the IP of our container is

As you can see the container is launched with the IP :

So Now our task is completed :)

GitHub Link :




computer engineering

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Testnet KYVE Mission Korellia

Table of Possibilities with Code Coverage and Functional Coverage

ANU #85 — New Version Launch and Layout Improvements

How to Import and Organize Audiobooks on Your Computer

Dlithe 12/04/2022 Experience

How to use Git and connect to GitHub

Code Monke #1: Measuring Latency in the Browser

Intro to System Administration: Part: 2

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
shivanand Patil

shivanand Patil

computer engineering

More from Medium

LeetCode — 1009. Complement of Base 10 Integer

The Fetch Method and Promise Based Functions

Winning with optimism

Introduction of: Max Johnson