How to install Ansible on Fedora 29 for IT and server automation


How do I install Ansible on Fedora 29 workstation? How can I set up and test Ansible playbooks using my Fedora Linux desktop?

Introduction – Ansible is a free and open source configuration management tool. It is similar to Chef or Puppet. It works over SSH based session and does not need any software or client/agent on remote servers. One can use Ansible to manage Linux, Unix, macOS, and *BSD family of operating systems. This page shows how to install ansible and set up your first Ansible playbook on Fedora Linux 29.

Procedure to install Ansible on Fedora 29

  1. Update your Fedora 29 system, run: sudo dnf update
  2. Install Ansible on Fedora 29, run: sudo dnf install ansible
  3. Upgrade Ansible in Fedora 29, run: sudo dnf upgrade ansible
  4. Set up ssh key-based authentication
  5. Test Ansible

Step 1. Fedora Linux install Ansible

Type the following dnf command to update Fedora box:
$ sudo dnf update
$ dnf search ansible

Find out information about the Ansible package, run:
$ dnf info ansible
Sample outputs:

Installing Ansbile on Fedora Linux

Finally, type the following dnf command:
$ sudo dnf install ansible
How to install Ansible on Fedora Linux using dnf command

Find the Ansible version

We can verify the Ansible version by running the following command:
$ ansible --version
Sample outputs:

First, create the key pair using the ssh-keygen command on your Fedora Linux desktop/workstation:
$ ssh-keygen -t ed25519 -C "Desktop ssh key"
Next, copy and install the public key in remote Linux/Unix/BSD servers using the ssh-copy-id command:
$ ssh-copy-id -i $HOME/.ssh/ [email protected]
$ ssh-copy-id -i $HOME/.ssh/ [email protected]
$ ssh-copy-id -i $HOME/.ssh/ [email protected]

Test password less log in using the ssh command:
$ ssh [email protected]
$ ssh [email protected]

Step 3. Test the Ansible

Sample Ansible Fedora Linux set up
Our sample Ansible setup

First create an inventory file as follows on a control machine:
$ vi inventory
Add hostnames/IP address of all remote Linux/*BSD servers:

Next run the uptime command command and lsb_release command on two hosts located in my LAN i.e. lanhosts group as user vivek:
$ ansible -u vivek -i inventory -m raw -a 'uptime' lanhosts
$ ansible -u vivek -i inventory -m raw -a 'lsb_release -a' lanhosts

Testing Ansible on Fedora Linux

Step 4. Writing your first Ansible playbook to manage Linux/Unix servers

First, update your inventory file to indicate user name and method to become sudo on the remote server. Here is my updated hosts file displayed with the cat command:
cat inventory
Sample config file:

A playbook is nothing but scripts/commands that executed on the remote box. Create a playbook named test.yml as follows using a text editor such as vim command/nano command:
vim test.yml
Append the following code:

Playbooks in Ansible use Yaml. Next, run it as follows from Fedora Linux workstation/control machine:
$ ansible-playbook -i inventory test.yml
How to run ansible playbook

A note about password stored in an insecure format

Take a close look at the following config directory in inventory file:

It is a bad idea to store password and other sensitive information in clear text format. Let us fix this:
$ vim inventory


Save and close the file. Next create a new encrypted data file named passwords.yml, run the following command:
$ ansible-vault create passwords.yml
Set the password for vault. After providing a password, the tool will start whatever editor you have defined with $EDITOR. Append the following:

Save and close the file. Run it as follows:
$ ansible-playbook -i inventory --ask-vault-pass --extra-vars '@passwords.yml' test.yml

Securely store password run Ansible playbooks on Fedora Linux
Click to enlarge

For more information read: How to set and use sudo password for Ansible Vault.

Adding user using the Ansible playbook

Say you need to add a new user named wwwjobs all hosts in lanhosts group. Create a new playbook named add-user.yml:

Run it as follows:
$ ansible-playbook -i inventory --ask-vault-pass --extra-vars '@passwords.yml' add-user.yml

How to add and remove packages

In this example, we are going to add and remove packages using the apt command for all hosts located in linodehosts group. Create a file named ubuntu-software.yml:

Again run it as follows:
$ ansible-playbook -i inventory --ask-vault-pass --extra-vars '@passwords.yml' ubuntu-software.yml


And there you have it, Ansible set up and tested to manage Linux or Unix boxes. Ansible works very fast for repeated tasks such as adding users in bulk, installing software, configuring *BSD/Linux/Unix boxes. YAML takes a little time to master but easy to learn. See Ansible documentation for more info:

  • Ansible documents
  • Linux user module document
  • Debian/Ubuntu apt module document
  • How to use Ansible vault to keep sensitive data such as passwords or keys in encrypted files

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *