How to Install and Use Ansible on Debian 10
Today, TipsMake will introduce the Ansible installation process on Debian 10.
Installing Ansible on Debian 10
To install Ansible on Debian 10, you need to do three simple steps:
Step 1: Update your Debian system 10
Before installing Ansible on Debian 10, you must update it using the command shown below:
sudo apt update
After updating your Debian 10 system, you should see information as shown in the following image on the Terminal:
Step 2: Install Ansible on a Debian 10 system
After the system update is finished, you can install Ansible on Debian 10 using the command shown below:
sudo apt install ansible
During the time this command is executed, you will see a message asking if you want to continue the installation on Terminal. You have to type Y in order for the installation to continue running smoothly.
When Ansible is successfully installed on a Debian 10 system, Terminal will generate some message on it similar to the one shown in the following figure:
Step 3: Confirming Ansible installation on a Debian 10 system
Installing Ansible on a Debian 10 system is so simple that it should complete in the two steps above. However, you can still verify if it was successfully installed on your Debian 10 system. This can be done by checking the Ansible's version with the following command:
ansible --version
The version of Ansible installed on a Debian 10 system in the example is 2.7.7.
Edit the file host / etc / ansible / hosts to add the system you want to manage with Ansible.
sudo nano /etc/ansible/hosts
Please add the following:
[TestClient] node1 ansible_ssh_host=192.168.0.12
And save the file.
Use Ansible
First, you must configure the SSH Key for the client node because Ansible is using the SSH protocol to pass commands to the client system.
Use this command to generate SSH key and key-based authentication:
ssh-keygen
Output:
Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:gTHiTCK.... root@debian10 The key's randomart image is: +---[RSA 2048]----+ | . . . | +----[SHA256]-----+
The next step is to copy the newly created key to another system. Run this command:
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.2
The IP 192.168.0.2 in the above command should be replaced with the IP address of the system you want to manage with Ansible.
Output:
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.168.0.2's password: Number of key(s) added: 1
Now that it's time to do the first test, log in to another machine using this SSH command:
ssh root@192.168.0.2
The login should now work without a password.
Test run Ansible
Installation is complete, now you can start testing Ansible
Run this command to test the connection:
ansible -m ping TestClient
Output:
node1 | SUCCESS => { "changed": false, "ping": "pong" }
In case you have defined multiple clients, you can check all connections with the following command:
ansible -m ping all
Now, it's time to run a command on the remote system and fetch the results. For this example, the df command will be used.
ansible -m shell -a 'df -h' TestClient
Output:
node1 | CHANGED | rc=0 >> Filesystem Size Used Avail Use% Mounted on udev 957M 0 957M 0% /dev tmpfs 195M 21M 175M 11% /run /dev/sda1 38G 11G 25G 31% / tmpfs 974M 0 974M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 974M 0 974M 0% /sys/fs/cgroup /dev/sda15 121M 130K 120M 1% /boot/efi tmpfs 195M 0 195M 0% /run/user/0
The results show the use of the hard drive on the remote system. You can execute any Linux shell command like this using Ansible and also create a complete script to set up and maintain the server.
You should read it
- How to Install Gradle on Debian 10
- Notable changes and additions in Debian 11 'Bullseye'
- Do not destroy the Debian system!
- Debian 10 Buster, New features in Debian 10 Buster
- How to Restart Debian Using the Command Line
- 9 best Debian-based Linux distributions
- How to Install Debian
- Configure mouse settings on the Debian system
May be interested
- How to install NVM on Debiannvm stands for node version manager. with nvm, you can manage multiple node.js instances of nodejs and switch between them without uninstalling and reinstalling the node.
- Notable changes and additions in Debian 11 'Bullseye'debian is one of the oldest, most stable and flexible linux distributions in the free and open source world.
- Do not destroy the Debian system!debian is a powerful and reliable system, but new users are still very easy to ruin the system, by not doing everything the way debian does.
- Debian 10 Buster, New features in Debian 10 Busterdebian 10 buster has been released. let's explore the new features in debian 10 buster through the following article!
- How to Restart Debian Using the Command Linethe linux operating system can run without a reboot not only for a few weeks but for years. but sometimes there's a good reason to reboot your linux system after a week or two, depending on the situation.
- 9 best Debian-based Linux distributionsfortunately, debian's flexibility has made it a good base for other distributions, providing a more pleasant experience for those new to linux.
- Configure mouse settings on the Debian systemdebian allows you to create as many configurations as possible in the system modules. in this article, tipsmake.com will describe how to configure mouse settings on a debian system.
- How to install and configure Samba on Debiansamba is a powerful open source tool that allows windows-like file and printer sharing on the network in linux systems.
- How to reset the password for sudo in Debianthe user password is changed in debian using the passwd command. in this article, tipsmake.com will explain how root users can change their own passwords on debian servers.
- How to upgrade from Debian 11 'Bullseye' to Debian 12 'Bookworm'if you are already using debian 11 bullseye, you can directly upgrade to debian 12 bookworm from the terminal.