Getting Started With Ansible

Last Updated: Feb. 17th 2022 at 6:34pm Tags: blog linux ansible docker

Here is a tutorial of how I would start a server from scratch using ansible and docker

In my previous article I showed how to install a “root” server onto a Virtualbox. The following tutorial should work for both 18.04 and 20.04 all ubuntu flavors as long as you have root access.

This is how you install Ansible on Ubuntu:


# Skip this step if you are running 20.04
# if you are running 18.04 you need this step:
# 20.04 is running version 2.9.6 at the time of writing
sudo apt-add-repository --yes --update ppa:ansible/ansible

# run this to install ansible
sudo apt install -y ansible

# if you are running xubuntu run this:
sudo apt install -y sshpass

Note: try this if you are having problems or using a slightly different flavor or older version of Ubuntu:

sudo apt install software-properties-common

Then re-run apt install Ansible.

Next I have my initial run playbook saved to my public Github account so I can just download and run it:

wget https://fbot.co/playbook -O firstplaybook.yml

ansible-playbook -i localhost, -u root -k firstplaybook.yml

Here is the Ansible playbook file that I download.

Note: In the playbook I’ve added my user to the docker group so I can run it not as root or using sudo.

-i option is for hosts list (it’s an array so make sure you have a comma) -u is user to use -k is to ask for password

That’s it, you have Ansible installed and you have docker installed, next let’s get git up and running.

Known Issues

If you receive the error:

fatal: [localhost]: FAILED! => {"msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."}

It means you have not logged into the server before and you need to add the server’s fingerprint to your known_hosts. Just login manually first:

ssh root@localhost

Resources

Comments

You need to login to comment.