fcarvw
Last Updated: February 25, 2016
·
7.004K
· mpdehaan
3c1b7e921632632e11d5d2ee59403f5f

See what variables you can use in templates

Various facts about the remote system are available as variables for use in templates. The easiest way to check what those values are is to execute the setup module on the remote host, like so.

ansible foo.example.com -m setup

You will get back JSON information with all of the values available.

centos2 | success >> {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.1.14"
        ], 
        "ansible_all_ipv6_addresses": [
            "fe80::20c:29ff:fe62:85d7"
        ], 
        "ansible_architecture": "x86_64", 
        "ansible_bios_date": "09/20/2012", 
        "ansible_bios_version": "6.00", 

This means in a playbook you can use variables like:

${ansible_architecture} 

or in a Jinja2 template this is just:

{{ ansible_architecture }}
Say Thanks
Respond

2 Responses
Add your response

4616
8bea982bbfcc5134d89eaad975277a4a

with ansible 0.9 if there is no /etc/ansible/hosts file on your executing host you will get a Traceback from Python complaining about the global inventory file being no present, if you don't have an /etc/ansible/hosts instead do a: 'ansible -i someinventoryfile foo.example.com -m setup'

over 1 year ago ·
4619
3c1b7e921632632e11d5d2ee59403f5f

@elee think maybe you wanted to start a new tip versus commenting on this one maybe.

Latest released is 1.0 and 1.1 is the current development branch, which doesn't present an error if that file is missing.

over 1 year ago ·
Filed Under