How to Use Ansible Magic Variables in Ansible Playbook
I’m going to show you a live demo and some simple Ansible code.
I’m Luca Berton and welcome to today’s episode of Ansible Pilot.
Ansible Magic Variables
How to Ansible Magic Variables in Ansible Playbook.
The good news is that Ansible provides some internal variables that come out of the box with some information such as running the Ansible version, inventory details, or execution options.
The path to the directory of the playbook that was passed to the ansible-playbook command line
The directory of the inventory source in which the inventory_hostname was first defined
The file name of the inventory source in which the inventory_hostname was first defined
The inventory name for the ‘current’ host is being iterated over in the play
Boolean that indicates if we are in check/diff mode or not
Dictionary/map that contains information about the currently running version of ansible, it has the following keys: full, major, minor, revision and string.
The full list is available on the official Ansible website https://docs.ansible.com/ansible/latest/reference_appendices/special_variables.html
How to use Ansible Magic Variables in Ansible Playbook?