Installing Ansible on Ubuntu or Debian is a straightforward process. Here’s a quick guide to get you started:
Step 1: Update Your System
Before you install any new software, it’s always a good idea to update your package lists. Open your terminal and run the following command:
sudo apt update
You may also want to upgrade your packages to the latest version with:
sudo apt upgrade -y
Step 2: Install Software Properties (Ubuntu Only)
If you’re on Ubuntu, you might need to install the software-properties-common
package, which adds the add-apt-repository
utility to your system. This utility makes it easier to add new software repositories. On Debian, this step is usually not necessary as the tool is typically included by default.
Run this command on Ubuntu:
sudo apt install software-properties-common -y
Step 3: Add The Ansible Repository
Ansible maintains its own Ubuntu PPA (Personal Package Archive). Add it to your system to ensure you get the latest version of Ansible:
sudo add-apt-repository ppa:ansible/ansible
For Debian, you can skip this step since Ansible is included in the default repositories, though it may not be the latest version.
Step 4: Install Ansible
Now, update your package lists again to include the packages from the newly added Ansible repository:
sudo apt update
Finally, install Ansible with:
sudo apt install ansible -y
Step 5: Verify the Installation
Check if Ansible has been installed correctly by running:
ansible --version
This command should display the version of Ansible that’s been installed on your system.
Step 6: Basic Configuration (Optional)
For a basic setup, you can configure Ansible to connect to your nodes by editing the /etc/ansible/hosts
file. Open the file in your favorite text editor, like so:
sudo nano /etc/ansible/hosts
Add your hosts under the [servers]
group, or any group name you prefer, like this:
[servers]
192.168.1.50
192.168.1.51
Replace the IP addresses with those of your own servers. Save the file and exit the editor.
That’s it! You’ve successfully installed Ansible on your Ubuntu or Debian system and are ready to start automating your infrastructure.