Ubuntu Install


sudo apt install python3-pip

pip3 install ansible

sudo apt install ansible

ansible --version

ansible 2.10.5

config file = /etc/ansible/ansible.cfg

configured module search path = ['/home/donald/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']

ansible python module location = /home/donald/.local/lib/python3.8/site-packages/ansible

executable location = /usr/bin/ansible

python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]


donald@Ansible1:~/ansible/testv1/inventory$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/home/donald/.ssh/id_rsa): ansible1key

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in ansible1key

Your public key has been saved in


sudo adduser ansible

#Now, configure password-less sudo access to the ansible user with the following command:

$ echo "ansible ALL=(ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/ansible

#Grab the IP

hostname -I


ssh-copy-id ansible@


donald@Ansible1:~$ ssh-copy-id -i .ssh/ ansible@

/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: ".ssh/"

The authenticity of host ' (' can't be established.

ECDSA key fingerprint is SHA256:wPP8O0WemEV7ghKaEJQSTmzNiYqfh5fqazXGBNi5j40.

Are you sure you want to continue connecting (yes/no/[fingerprint])? yes

/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

ansible@'s password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'ansible@'"

and check to make sure that only the key(s) you wanted were added.


Now, disable password-based login for the ansible user with the following command:

sudo usermod -L ansible

If for some reason, you want to allow password-based login for the ansible user again, run the following command

sudo usermod -U ansible


#check the connection

ssh -i .ssh/ansible1key ansible@

#test ansible

mkdir /home/donald/ansible/linuxv1

#inside the above directory

nano hosts

#create ansible config file

nano ansible.cfg


private_key_file = /home/donald/.ssh/

donald@Ansible1:~/.ssh$ cp

donald@Ansible1:~/.ssh$ cp ansible1key id_rsa

#test Ansible

donald@Ansible1:~/ansible/linuxv1$ ansible all -i ./hosts -u ansible -m ping | SUCCESS => {

"ansible_facts": {

"discovered_interpreter_python": "/usr/bin/python3"


"changed": false,

"ping": "pong"


ansible all -i ./hosts -u ansible -m ping

ansible all -i ./hosts -u ansible -m shell -a 'echo "$(hostname) - $(hostname -I)"'

ansible all -i ./hosts -u ansible -m shell -a "df -h"

#this is how you would check the uptime of every host in the servers group:

ansible servers -a "uptime" -u root or ansible all -i ./hosts -u ansible -a "uptime"

#We can specify multiple hosts by separating them with colons:

ansible server1:server2 -m ping -u root

#As an example, this will use the apt module to install the package tree on server1:

ansible server1 -i inventory -m apt -a "name=tree"

#As an example, this will use the apt module to install the package tree (-b use sudo)

ansible all -i ./hosts -u ansible -m apt -a "name=tree" -b

Playbook Test

donald@Ansible1:~/ansible/linuxv1$ cat playbook1.yaml

- hosts: docker_servers


- name: Ansible apt install packages example

become: true

# become_user: ansible



- dnsutils

- speedtest-cli

state: present

update_cache: true

donald@Ansible1:~/ansible/linuxv1$ cat hosts


donald@Ansible1:~/ansible/linuxv1$ cat ansible.cfg


remote_user = ansible

inventory = /home/donald/ansible/linuxv1/hosts

donald@Ansible1:~/ansible/linuxv1$ ansible-playbook playbook1.yam


How To Install and Configure Ansible on Ubuntu 20.04

Click the button below for F5 nuggets