How to install ansible on Debian 10

Ansible is an open-source automation tool, or platform, used for IT tasks such as configuration management, application deployment, intraservice orchestration, and provisioning.

In this tutorial, we learn how to install ansible on Debian 10 using the package that is available on Debian 10 sources.

Official documentation: https://docs.ansible.com/

Installation

  • Update apt index package and install ansible
sudo apt -y update
sudo apt -y install ansible
  • Wait for command to complete and check that package was installed properly
catalin@devops:~$ ansible --version
ansible 2.7.7
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/catalin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]

How it works ?

Let’s say that you just started a new Debian 10 machine where you installed ansible. You have already a second machine and want to deploy stuff using ansible. By default, ansible is using root account but you can configure also a user with sudo privileges.

Give root account ssh access on the node where you and to do things with ansible (add public key in /root/.ssh/authorized_keys file on the second node). If you don’t have a key, generate one.

ssh-keygen -o -t rsa -b 4096 -C "root@hostname"

By default, this key pair will be generated in /root/.ssh, id_rsa, and id_rsa.pub. After adding the public key on the node test that ssh is working.

catalin@devops sudo ssh root@ip_second_node

The next step is to add the IP of the node in our host file which is located in /etc/ansible/hosts.

[dev]
10.0..0.4

Ansible offers two possibilities, to run ad-hoc commands or to group multiple tasks, playbooks. I’m gonna run some ad-hoc commands.

Try to check if server responds to ping.

catalin@devops:/etc/ansible$ sudo ansible dev -m ping
10.0.0.4 | SUCCESS => {
    "changed": false,
    "ping": "pong"
}


catalin@devops:/etc/ansible$ sudo ansible dev -a "uptime"
10.0.0.4 | CHANGED | rc=0 >>
 15:06:19 up 23:51,  2 users,  load average: 0.21, 0.06, 0.02

Check the documentation and have fun exploring it.