Ansible-查看主机所有内置变量

打印所有变量:

- 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值