ARTICLE

Classes: Install and Configure Ansible

24 February 2021 by Andi Wirawan

Previously we have intorduced Ansible. Therefore, this article will discuss about how to install and configure Ansible on linux.

In short, Ansible is an agentless automation tool that is using SSH and python to manage remote servers. It does not need database server or running as daemon or service. You can easily install on a server or a laptop and that’s it, after that you can start using Ansible to manage an entire fleet of remote servers from your laptop.

When Ansible manages remote machines, it does not leave software installed or running on them. So there’s no real question about how to upgrade Ansible when moving to a new version. In addition, currently Ansible can be run from any machine with Python 2 (version 2.7) or Python 3 (versions 3.5 and higher) installed.

Ansible only needs python2 (version 2.7) or python3 (version 3.5 and higher) installed on the remote servers to manage them and that’s it, no need other software or service that is why it’s called agentless.

Therefore, to understand better please take a close look on how to install and configure Ansible on linux below.

Installing Ansible on Linux

  • On Fedora:
$ sudo dnf install ansible 
  • On RHEL and CentOS:
$ sudo yum install ansible 
  • On Ubuntu:
$ sudo apt update 
$ sudo apt install software-properties-common
$ sudo apt-add-repository --yes --update ppa:ansible/ansible
$ sudo apt install ansible

Once you have installed the ansible, run command below to make sure that ansible is installed properly.

$ ansible --version

Then, you will see the output would be something like below.


ansible 2.9.16
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Sep 30 2020, 13:38:04) [GCC 7.5.0]

Due to the output, we could see that ansible has a configuration that can be optimized as your need at /etc/ansible/ansible.cfg
By default, the configuration is enough for you to make an ansible role as well as ansible read the ssh keys form ~/.ssh/id_rsa. Although It depends on what users are logging in, you still can optimize that on [ssh_connection] section. Not only you can make it more fun with optimizing the color of your ansible output, but also change it in [colors] section as well.

As I mentioned in the previous classes, you need to follow ansible hierarchy to make ansible running well. By default, ansible already created files on /etc/ansible path for inventory and roles, but you can move it to your desired path.

Ansible hierarchy

  • Inventory: this file is for inventory list of your server. You can group it with server function or roles.
    Example format:
    [allserver]
    192.168.20.1
    192.168.20.2
    192.168.20.3
    192.168.20.4

    [lb_server]
    192.168.20.1
    192.168.20.2
  • Group_vars: here we assign variables to particular groups
    This will be applied to all server when ansible runs
    Example format:
    ntpserverip: ntp.domain.com
    rsyslog_version: ‘*’
  • Host_vars: if systems need specific variables, put them here.
    This will be applied to some server that defined in this path.
    Thus, the file should be named with the IP listed in the inventory
    Example format:
    host_name: lb-vm1
    host_domain: domain.com
    full_host_name: “{{ host_name }}.{{ host_domain }}”
    ip_address: 192.168.20.1
  • site.yml: master playbook
    This file will be called in the first time when running ansible-playbook
    In this file, you need to define what role and which server will be executed. Then, you need to save the file as yml format.
    Example format:
    hosts: allserver
    gather_facts: false
    roles:
    – usergroup
  • roles: list of role and script that will be executed.

So, do you want to know how to use the ansible?
Please follow this link.

0 0 votes
Article Rating

Ready to Make Something Big?

Deploy in Cloud Raya