Ansible Tips and Tricks ( Part 1 )

A little bit about myself, I am DevOps Engineer and I have around 4 years of experience in Ansible since version 2.2 / 2016. I have done 50+ projects in Ansible.

I will be sharing tricks that I learnt over time while using Ansible.

Trick 1: Variable Inside Another Variable

So let’s suppose you one variable or result which is being generated by some task. Now you want to use that Result / Variable Inside another variable to generate some value or another result.

Above Syntax won’t work.

Let’s take an example and see.

Try 1:

I will add curly brackets inside another curly bracket like a lazy developer.

Try 2:

I keep curly brackets inside another curly bracket but will add single quotes to inside brackets to make it separate.

Try 3:

Ansible has a special syntax for it which is to use square brackets and without any curly brackets on the inside variable, Ansible Engine will automatically populate inside variable first then outside variable.

It can be enhanced a bit more to make it simple to understand and faster execution.

Try 4:

Add Type of inside variable like Int / String / etc .

Have a fun day! and Keep Learning.



Principal Software Architect I ( R&D DevOps )

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store