Ansible – Quick high level run through of components that make up ansible, and how to find help docs via the CLI!

Ansible_logo.svg

This will be a deeper dive into the different Files / Dependencies within Anisble

I’ve gotten Ansible running on my home lab, but never entirely understood things like the Hierarchy of files and what depends on what, so I wanted to hit the learning lab and jot down Ansible Specific notes here for configuration.

Note the same Ansible Lab and many other labs can be found at the link below:

https://developer.cisco.com/learning/modules?keywords=ansible

I didn’t find any sandboxes for Ansible, though I imagine you can probably spin up a NX-OS Lab to execute an Ansible Home lab against, I haven’t tried it yet but I would definitely be familiar with that and all sites for the DEVASC exam (as it is a topic!)

The Inventory File – ansible.cfg file

This can be found at its default location /etc/ansible/ansible.cfg in Ubuntu and probably most flavors of Linux, and within this file is where you can set the Parameters of how Ansible works though I’ve so far not touched a whole lot to not break it until the end of my DevNet Bootcamp class.

I don’t know that I have touched this file yet beyond trying to set “derpricated_version_warning” parameter from True to False so it would quit throwing an error that my Ubuntu Hosts / Ansible was invoking Python 2 when communicating to them, however there are a ton of Parameters in here.

The two main components I see in this lab is:

inventory = localhost
host_key_checking = False (or True if your Host has SSH Keys installed)
roles_path = ./ (This points to the /roles files for its Playbook)

Generally if you do a “sudo pip install ansible” or “sudo apt install ansible” this config file will already be filled in with most everything you will need to start with.

The Ansible Playbook

This will be a YAML file on the local host called “checklocalinfo.yml” which will contain the following Parameters as components of the file itself:

ansdemo1

  • name: – The name of the “Play” which should be intuitive to read so others can understand the task being performed by reading just this line
  • hosts: – This will refer to specific Hosts in the “Host File” which can refer to a single host, a group of hosts, or the parent name of a group of children (host groups)
  • connection: – Because this is on the host it is local, but others would be remote host name via FQDN or IP Address
  • tasks: – This defines another Task in the “Play” being executed top down
  • – name: – This will give a friendly name to print out before task output
  •   debug: msg={{ansible_hostname}} – One of many tasks that can be added to a play, the debug will gather general output from its target to return as seen below

ansdemo2

First the “Play” gets executed, then it runs tasks in order which first connection to the host, then displaying the “name” in the task list, then the debug output which will vary from device to device.

You can add multiple tasks to be executed in the play by adding an additional indented -name: “Some task” / (task): msg=(something) to continue gathering facts or writing configs to the target.

For example I added a second Task to my lab and got the output shown here:

ansdemo3

And out running “ansible-playbook -i (hosts) checklolcalinfo.yml” :

ansdemo4

It can be seen you can continue added different tasks as needed by naming them, then defining the task, and it will do a “Play Recap” to show how many tasks succeeded / failed / unreachable / changed / ignored / etc at the very bottom of the output returned.

When really cool Ansible feature – On-demand CLI powered documentation!

From the Bash Prompt you can type in “ansible-doc aci-rest” as a module name for rest-aci and it will spit output of examples of tasks, example of returned output, etc.

To see a full list of modules (which is very very long so be prepared) “ansible-doc -l modules” to get all different modules present to get documentation for, and you can also just do “ansible-doc” to get started  with the commands and options to navigate the CLI.

Also the module information can be found at https://docs.ansible.com

I will need to cut it short here as I am getting off track from homework!

I am started to build some plays and found you can run Play Books in AWS Servers which I also noticed in the dashboard, and the day is flying by with me playing inside Ansible while I have Automation sections to get through for me class.

I’ll fill this in a bit more when I get time to play with Ansible!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s