This content originally appeared on DEV Community and was authored by Wycliffe A. Onyango
Why and How to Install Ansible
Ansible is a powerful automation engine used for configuration management, application deployment, and task automation. It’s a key tool for system administrators and DevOps teams because it simplifies complex tasks, ensuring consistency across servers. A major advantage of Ansible is that it’s agentless, meaning you don’t need to install any special software on the managed machines. It connects over standard SSH, which makes it easy to set up and use.
Installation on a Jump Host
A jump host (or bastion host) is a secure server that acts as an intermediary to access other servers in a private network. Installing Ansible on a jump host allows a single point of control to manage all other systems, centralizing automation efforts and enhancing security.
To install Ansible, the recommended method is using pip
, Python’s package installer. pip
ensures all dependencies are correctly handled. Since Ansible is built on Python, pip
is a reliable choice.
Global Installation Using sudo pip
A simple way to install Ansible globally is by using sudo pip install
. This command installs packages into the system-wide Python environment, making them available to all users without needing to modify the PATH
environment variable.
However, using sudo pip install
is often discouraged because it can lead to conflicts with the system’s package manager (like apt
or yum
). These conflicts can cause system corruption and version mismatches.
To install a specific version of Ansible globally, use the following command:
sudo pip install ansible==<version>
Fixing the PATH for All Users
After a user-level installation, Ansible’s binary might only be available to the user who installed it. To make Ansible globally accessible, its installation directory must be added to the system’s PATH
environment variable. The PATH
is a list of directories the operating system searches for executable files.
Here’s how to fix this for all users on a jump host:
Method 1: Edit /etc/profile
This method affects all users when they log in to a shell.
-
Add the directory to the
PATH
: Use the following command to append/usr/local/bin
to thePATH
variable in/etc/profile
. This ensures the change is permanent and applies to all new login sessions.
sudo sh -c 'echo "export PATH=\$PATH:/usr/local/bin" >> /etc/profile'
-
Apply the changes: To use the new
PATH
in your current session without logging out, source the file.
source /etc/profile
Method 2: Update /etc/environment
This file is used by all processes and is often considered a more robust way to set a global PATH
.
-
Open the file: Use a text editor like
vi
withsudo
to edit/etc/environment
.
sudo vi /etc/environment
-
Add the path: Find the line starting with
PATH=
and add/usr/local/bin
to the list, separated by a colon.
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Save and exit: Save the changes and log out, then log back in for the new
PATH
to take effect.
Verification
After making these changes, you can verify that Ansible is globally available by running the following commands, which should now work for any user on the system:
which ansible
ansible --version
This content originally appeared on DEV Community and was authored by Wycliffe A. Onyango