Where can I get a list of Ansible pre-defined variables?

后端 未结 10 2281
谎友^
谎友^ 2020-12-04 05:15

I see that Ansible provide some pre-defined variables that we can use in playbooks and template files. For example, the host ip address is ansible_eth0.ipv4.address. Googlei

10条回答
  •  离开以前
    2020-12-04 05:32

    I use this simple playbook:

    ---
    # vars.yml
    #
    # Shows the value of all variables/facts.
    #
    # Example:
    #
    #   ansible-playbook vars.yml -e 'hosts=localhost'
    #
    - hosts: localhost
      tasks:
        - fail: "You must specify a value for `hosts` variable - e.g.: ansible-playbook vars.yml -e 'hosts=localhost'"
          when: hosts is not defined
    
    - hosts: "{{ hosts }}"
      tasks:
        - debug: var=vars
        - debug: var=hostvars[inventory_hostname]
    

提交回复
热议问题