--- - hosts: db vars: vvv: china tasks: - name: test var debug: msg="The variable ‘vvv‘ is {{ vvv }}"
--- - hosts: db vars_files: - vars.yml tasks: - name: test var in file debug: msg="The variable ‘kk‘ is {{ kk }}"
---
kk: lile
[db] 10.0.0.147 pp=ppppppp [db:vars] mm=heiheihei
--- - hosts: db tasks: - name: test hosts group var debug: msg="The Variable ‘mm‘ is {{ mm }}" - name: test singer var debug: msg="The Variable ‘pp‘ is {{ pp }}"
--- tt: yyyyyyyyyyyyy
而後就能夠使用了
--- - hosts: db tasks: - name: test /etc/ansible/group_vars debug: msg="The variable ‘tt‘ is {{ tt }}"
--- - hosts: db tasks: - debug: msg="Variable ‘tt‘ is set to {{ hostvars[‘10.0.0.146‘][‘ttt‘] }}"
--- - hosts: db tasks: - name: test hostvars debug: var=hostvars[‘10.0.0.146‘][‘ttt‘]