Getting Back Into Ansible

netscape101
DevOpsOnTheBlock
Published in
2 min readAug 22, 2019

I was really into Ansible at some point, but it really never picked up. Not because I didn’t want it to, I just became busy with other things and the need for Ansible specifically wasn’t that huge at that moment. Right now I have a use case to extensively use it again. I used to run a wiki which sadly is down at the moment, so instead of salvaging my outdated notes I created new notes.

Install Ansible:

I quickly glanced over this excellent article: https://serversforhackers.com/c/an-ansible2-tutorial for some inspiration

$ sudo pip3 install virtualenv$ mkdir ~/Desktop/ansible$ cd ~/Desktop/ansible$ virtualenv .venv$ source .venv/bin/activate(.venv) $ pip install ansible

Configure Ansible:

Create your config:

$ vim ~/.ansible.cfg

This goes in your config:

[defaults]
inventory=~/ansible/hosts

All the above does is tells ansible where your hosts inventory will be. Some people create a directory in /etc/ for their ansible configs, but I prefer to have it in my home directory as I don’t need any special permisions to edit the config files if they are in my home directory. The host inventory houses the list of servers or machines that you plan to manage with ansible.

Next create an ansible directory:

$ mkdir ~/ansible$ touch ~/ansible/hosts

Your hosts inventory should look something like this:

[primary-server]
myserver.com ansible_ssh_user=sysadmin

For now I only have that one server that I play around with, but you might have more.

You can also group your servers in your host inventory , this is handy if you have a bunch of clients and each has their own set of servers that you need to make changes on.

Now for that hello-world magic:

Run playbook from hosts inventory:

$ ansible-playbook -i ~/ansible/hosts site.yml -vvvv

Cool Colour Prompt:

If you want a cool colour promt in your terminal like me just add this to your ~/.bash_profile on OSX:

export PS1="\[\033[1;36m\]me\[\033[01;37m\]@\[\033[01;34m\]me\[\033[01;30m\][\[\033[01;37m\]\w\[\033[01;30m\]]\[\033[01;32m\]\[\033[00m\]+ "

We spell “color” as “colour” in South Africa so don’t hate on me :)

Thanks for reading!

--

--