打印所有变量:
- name: print all 内置 vars
debug: var=hostvars[inventory_hostname]
TASK [test : print all 内置 vars] *********************************************************
ok: [192.168.0.133] => {
"hostvars[inventory_hostname]": {
"NODE_N": 123,
"ansible_all_ipv4_addresses": [
"192.168.0.133",
"192.168.0.228"
],
"ansible_all_ipv6_addresses": [],
"ansible_apparmor": {
"status": "disabled"
},
"ansible_architecture": "x86_64",
"ansible_bios_date": "12/01/2006",
"ansible_bios_version": "VirtualBox",
"ansible_check_mode": false,
......
下面方法也可以
- name: print 内置变量
debug: var=ansible_facts
或
ansible hostname -m setup
打印IP
- name: print ip
debug: var=hostvars[inventory_hostname]['ansible_all_ipv4_addresses'][0]
TASK [test : print ip] *********************************************************
ok: [192.168.0.133] => {
"hostvars[inventory_hostname]['ansible_all_ipv4_addresses'][1]": "192.168.0.228"
}
参考:
https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html