In this guide, we will show you how to install Ansible (Automation Tool) on Debian 12 system.
Ansible is a free and open-source automation tool. It is used for configuration management and application deployment. Ansible is available for almost all UNIX like operating systems.
System on which Ansible is installed is known as ‘Control Node’ and systems which are being managed by ansible are known as ‘managed host’. Ansible does not need any agent on managed hosts as it works on ssh protocol (default port 22).
For the demonstration purpose, I am using following Lab.
- Ansible Control Node – 192.168.1.151 (control.example.net) – Debian 12
- Managed Host 1 – 192.168.1.170 (host1.example.net) – Rocky Linux 9
- Managed Host 2 – 192.168.1.180 (host2.example.net) – Rocky Linux 9
Minimum System Requirement for Ansible
- Minimal Debian 12 System
- Sudo User with root privileges
Let’s deep dive into Ansible Installation steps on Debian 12
1) Install Ansible (Automation Tool) on Debian 12
Ansible Debian package and its dependencies are available in the default Debian 12 package repositories. So, to install ansible, run following commands
$ sudo apt update $ sudo apt install ansible -y
Once ansible is installed, verify its version by running,
$ ansible --version
Above output confirms that ansible version 2.14.3 is installed.
2) Generate SSH keys and share it between managed hosts
To generate ssh keys, run ‘ssh-keygen’ command
Now exchange ssh keys using ssh-copy-id command,
$ ssh-copy-id 192.168.1.170 $ ssh-copy-id 192.168.1.180
On each managed host, configure following for sysops user so that it can run sudo commands without prompting password.
$ echo "sysops ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/sysops
3) Create ansible config file and inventory file
Let’s create project folder with name ‘ansible-demo’,
$ mkdir ansible-demo $ cd ansible-demo/
Create ansible.cfg file with following content
$ vi ansible.cfg [defaults] inventory = ./inventory host_key_checking = false remote_user = sysops ask_pass = False [privilege_escalation] become=true become_method=sudo become_user=root become_ask_pass=False
Save and exit the file.
Create the inventory file,
$ vi inventory [prod] 192.168.1.170 [dev] 192.168.1.180
Save & close the file
Now in ‘ansible-demo’ folder we have two files, ansible.cfg and inventory
$ pwd /home/sysops/ansible-demo $ ls -l total 8 -rw-r--r-- 1 sysops sysops 193 Dec 30 12:24 ansible.cfg -rw-r--r-- 1 sysops sysops 42 Dec 30 12:25 inventory $
4) Test and Verify Ansible Installation
Let’s first verify the managed host connectivity from ansible control node, run following ansible ad-hoc command
$ ansible all -m ping
Perfect, above output confirms ansible is able to perform ping pong test to its managed hosts.
Let’s create a sample playbook to install Apache server on dev node
$ vi demo-nginx.yml --- - name: Install NGINX Web Server hosts: dev tasks: - name: install nginx package yum: name: nginx state: installed - name: Start nginx service service: name: nginx state: started
save & exit the file
To run the playbook, execute following command
$ ansible-playbook demo-nginx.yml
Verify whether nginx is installed and started on Dev host, run following ansibe ad-hoc commands
$ ansible dev -m shell -a 'rpm -qa | grep -i nginx' $ ansible dev -m shell -a 'systemctl status nginx'
Great, above output confirms that playbook has been executed successfully on dev host. That’s all from this guide, we hope you have found it informative and useful. Feel free to post your queries and feedback in below comments sections.
Read Also: How to Install Microsoft Teams on Ubuntu/Debian Linux