Initial Ansible Install on Ubuntu

Because I have to run this on any new Ansible or Vagrant machine, here’s a note to myself to make this a little faster.

For Ubuntu Linux machines

sudo apt-get --assume-yes install nano man git python # For a new, minimal install of Ubuntu, e.g a Vagrant Box, they don't even include a ~/.bashrc file nor nano or man, this can help. Also, Ansible needs python (version 2 not 3) to run.
sudo apt-get --assume-yes install software-properties-common
sudo apt-add-repository --yes ppa:ansible/ansible
sudo apt-get --assume-yes update
sudo apt-get --assume-yes install ansible


Also ensure the hostname is something you want. Here’s a 1 liner I use, just set the hostname to something you want :
NEW_HOSTNAME=''; echo ${NEW_HOSTNAME} > /etc/hostname; echo " ${NEW_HOSTNAME}" >> /etc/hosts; hostname ${NEW_HOSTNAME};

# Don’t forget to copy over the ~/.ssh/config and ~/.ssh/*.pem files across, although you probably have an Ansible task for that.


Hopefully you are hosting your Ansible playbooks and other files in a git repo, so you should be able to clone that and start using it.

Once you’ve setup your /etc/ansible/hosts file (I usually copy mine from my Git repo) you can try ssh’ing into all the servers. You’ll want to ensure you have run ssh-copy-id and logged in if you usually connect to the machine via a password, or have the vars for the pem file(s) set, especially if connecting to an AWS machine via ssh keyfile.

After that you’ll likely want to run the command below which will automatically say ‘yes’ to all the requests to add the server’s SSH key. This assumes your flavour of Linux has the ‘yes‘ command.

yes yes | ansible all -m ping

Leave a Comment