Tag: Ansible

Let's talk about passing extra Playbook variables from command line. First off, why would you want to do it? Maybe you want to execute task only if a variable is defined, which is handy for debugs and tasks with additional processing. Or maybe you have a more generic playbook that can work with more than one version of OS, and you want your user to decide which one OS he wants to run Playbook for. I will show in this post how we can tackle both of these problems. Contents Introduction to extra variables Execute task when variable is defined...

Continue reading »

When running tasks Ansible allows you to access facts about host currently being processed. These could be facts discovered by Ansible itself or loaded from the files in the host_vars directory. This is something that we use all the time and is fairly intuitive. Sooner or later you will probably find out that some of your tasks, or data models, could be made simpler if you could access another host's facts, not just the ones belonging to the host Ansible is currently processing. As it happens, this is possible by using something Ansible calls magic variables. The particular variable...

Continue reading »

Ansible - ipaddr filter

Ansible's ipaddr filter is something you will be using a lot when working with network devices and their configurations. This filter provides an interface to netaddr Python package and it allows you to do almost anything that package can do, which is to say, a lot. You need to have netaddr library installed on your machine, Ansible filter won't work without it. I will show a few examples of how this filter could be used. You can refer to Ansible documentation [1] for the full list of available options. Contents: Check if the string is a valid IP address Get...

Continue reading »

While using loops in Ansible, by default, output contains the entire content of the item being processed. This can result in a great amount of verbosity if the item is a dictionary or is otherwise long. For example, when looping through the output of the "show ip bgp sum", we want to use just an IP of the peer as an input in another task. When "Get routes for each of the BGP peers" task executes Ansible will display the entire data structure linked to that peer. Task with the loop: - name: Get routes for...

Continue reading »

Problem The other day one of my playbooks reported an issue with connecting to one of the switches. What seemed odd is that the this playbook ran against this box without any problems ten minutes earlier. I double checked my password and all the permissions, all seemed to be in order. Just as a test, I tried to run this playbook for other devices, worked like a charm. It was time to turn the debug and full verbosity (-vvvv), on. Here's what I found in the logs: 2017-10-08 11:24:01,589 p=30940 u=przemek | PLAYBOOK: arista_test.yml...

Continue reading »