Search code examples
ansiblehostvars

Ansible - hostvars from single host


i have in the inventory host with own variables:

children:     
    webserver:
      vars:        
      hosts:
        web01.local:
          function: live
          location: lca         
        web02.local:
          function: test
          location: lcb

now i would like to create a playbook, which installs the snmpd service on each of the hosts (all) and stores the value "location" from the inventory.

How can I access this variable "location" in the playbook?


Solution

  • If your playbook is targeting the remote hosts, you can just refer to the location variable:

    - hosts: webserver
      tasks:
        - debug:
            msg: "value of location: {{ location }}"