Thursday, January 2, 2020

Ansible Installation, Playbook, Roles, Commands

What is Ansible?

Ansible is an automation and orchestration tool popular for its simplicity of installation, ease of use in what concerns the connectivity to clients, its lack of agent for ansible clients and the multitude of skills.
Ansible functions by connecting via SSH to the clients, so it doesn't need a special agent on the client-side, and by pushing modules to the clients. The modules are then executed locally, on the client-side, and the output is pushed back to the Ansible server.
Since it uses SSH, it can very easily connect to clients using SSH-Keys, simplifying though the whole process. Client details, like hostnames or IP addresses and SSH ports, are stored in files called inventory files. Once you have created an inventory file and populated it, ansible can use it.

Why use Ansible?

Here are some important pros/benefits of using Ansible
  • One of the most significant advantages of Ansible is that it is free to use by everyone.
  • It does not need any special system administrator skills to install and use Ansible, and the official documentation is very comprehensive.
  • Its modularity regarding plugins, modules, inventories, and playbooks make Ansible the perfect companion to orchestrate large environments.
  • Ansible is very lightweight and consistent, and no constraints regarding the operating system or underlying hardware are present.
  • It is also very secure due to its agentless capabilities and due to the use of OpenSSH security features.
  • Another advantage that encourages the adoption of Ansible is its smooth learning curve determined by the comprehensive documentation and easy to learn structure and configuration.

Important terms used in Ansible

  • Ansible server:

    The machine where Ansible is installed and from which all tasks and playbooks will be ran
  • Module:

    Basically, a module is a command or set of similar commands meant to be executed on the client-side
  • Task:

    A task is a section that consists of a single procedure to be completed
  • Role:

    A way of organizing tasks and related files to be later called in a playbook
  • Fact:

    Information fetched from the client system from the global variables with the gather-facts operation
  • Inventory:

    File containing data about the ansible client servers. Defined in later examples as hosts file
  • Play:

    Execution of a playbook
  • Handler:

    Task which is called only if a notifier is present
  • Notifier:

    Section attributed to a task which calls a handler if the output is changed
  • Tag:

    Name set to a task which can be used later on to issue just that specific task or group of tasks.

Ansible Installation in Linux

Once you have compared and weighed your options and decided to go for Ansible, the next step is to have it installed on your system. We will go through the steps of installation in different Linux distributions, the most popular ones, in the next small tutorial.

Install Ansible on Centos/RedHat systems

Step 1) Install EPEL repo
[root@ansible-server ~]# sudo yum install epel-release
Step 2) Install ansible package
[root@ansible-server ~]# sudo  yum install -y ansible

Install ansible on Ubuntu/Debian systems

Step 1) Perform an update to the packages
$ sudo apt update
Step 2) Install the software-properties-common package
$ sudo apt install software-properties-common
Step 3) Install ansible personal package archive
$ sudo apt-add-repository ppa:ansible/ansible
Step 4) Install ansible
$ sudo apt update
$ sudo apt install ansible

Ansible ad-hoc commands

One of the simplest ways Ansible can be used is by using ad-hoc commands. These can be used when you want to issue some commands on a server or a bunch of servers. Ad-hoc commands are not stored for future uses but represent a fast way to interact with the desired servers.
For this tutorial, a simple two servers hosts file will be configured, containing host1 and host2.
You can make sure that the hosts are accessible from the ansible server by issuing a ping command on all hosts.
[root@ansible-server test_ansible]# ansible -i hosts all -m ping
host1 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
host2 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

No comments:

Post a Comment

Networking terms in basic level

Basics of Computer Networking Open system: A system which is connected to the network and is ready for communication. Closed system...