ansible setup模块


[root@blog ~/project1 01:59:14]$ansible 192.168.85.251 -m debug -a "msg={{ ansible_default_ipv4 }}" -i hosts   # ad-hoc 方式执行debug 模块,无法调用facts变量
192.168.85.251 | FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'ansible_default_ipv4' is undefined"
}
[root@blog ~/project1 01:59:25]$ansible 192.168.85.251 -m setup -a "filter=ansible_default_ipv4.macaddress" -i hosts
192.168.85.251 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false
}
[root@blog ~/project1 02:01:10]$ansible 192.168.85.251 -m setup -a "filter=ansible_default_ipv4" -i hosts
192.168.85.251 | SUCCESS => {
"ansible_facts": {
"ansible_default_ipv4": {
"address": "192.168.85.251",
"alias": "ens33",
"broadcast": "192.168.85.255",
"gateway": "192.168.85.2",
"interface": "ens33",
"macaddress": "00:0c:29:9b:0f:90",
"mtu": 1500,
"netmask": "255.255.255.0",
"network": "192.168.85.0",
"type": "ether"
},
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false
}
[root@blog ~/project1 02:01:44]$ansible 192.168.85.251 -m setup -a "filter=ansible_default_ipv4.macaddress" -i hosts  # ad-hoc setup模块,不能取下一级变量
192.168.85.251 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false
}
[root@blog ~/project1 02:02:23]


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM