Introduction to Ansible and Basic Ansible Commands

Introduction to Ansible

  • It is an open source tool for configuration management and application-deployment
  • Agent less server automation tool uses SSH to connect to other servers
  • Installed on control node, with no agents to install on remote systems.
  • We can run the tasks in parallel
  • Supports multiple OS and cloud platforms

Key Concepts

  • Control Node – A node on which ansible is installed, inventory is defined and playbooks are deployed
  • Managed Node – Nodes which are connected to Control Node using ansible commands or playbooks
  • Inventory – All managed nodes defined in a file as a groups
  • Module – Component of ansible to perform common administrative tasks – E.g.: file, user, synchronize etc.
  • Task
  • Play Book
  • Ansible Tower

Control Node Requirement

  • Linux (Red Hat, Debian, CentOS) or macOS host with python 2 or 3 installed
  • Windows is not supported as Control Node

Managed Node Requirement

  • Python 2 or 3 should be installed
  • If you have SELinux enabled on remote linux nodes, you will also want to install libselinux-python using the below command
yum install -y libselinux-python

Installing Ansible on Control Node

In Linux systems, by default Python 2 will be avaialble. If you want to install ansible on top of Python 2, we can directly use below yum install command.

yum install -y epel-release
yum install -y ansible
Ansible install with python 2

Verify the ansible version using the below command

ansible --version
Ansible with python 2

Ansible with Python 3

yum install -y python3   #To install python3 on red hat based systems

python3 will install python3-libs, python3-pip, python3-setuptools and libtirpc packages also.

To install ansible on python 3 use the below command

pip3 install ansible
pip3 install ansible command

Once ansible is installed, check the ansible version using below command.

ansible --version
Checking the ansible version

Basic Ansible Commands

Here are some ansible ad-hoc commands:

Execute the hostnamectl command from ansible to get the hostname and related information.

ansible localhost -m shell -a "hostnamectl"
ansible localhost -a "hostnamectl"   #The default module is shell, we can use this
ansible ad-hoc command
Ansible command to get the hostname

Using ansible ping module

ansible localhost -m ping
Ansible Ping Module
0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like