# 官方提供@yunTaoScripts Ansible 清单文件 🔥🔥
# 指定清单文件
[root@rhel8-81 task2]# ansible -i hosts.bak xyt -m ping
rhel8-82 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
rhel8-83 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
# 包含主机组
[root@rhel8-81 task2]# ansible -i hosts.bak zz --list-hosts
hosts (4):
rhel8-84
rhel8-85
rhel8-86
rhel8-87
[root@rhel8-81 task2]# cat hosts.bak
[xyt]
rhel8-84
rhel8-85
[abc]
rhel8-86
rhel8-87
[zz:children]
xyt
abc
# 变量优先级
- 在 xyt 主机组的 的主机 会应用 group_vars 文件夹下的配置。
[root@rhel8-81 task2]# mkdir group_vars/xyt
[root@rhel8-81 task2]# pwd
/root/ansible/task2
[root@rhel8-81 task2]# ls | grep group_vars/xyt/main.yaml
优先级顺序 role_var > playbook_var > group_vars(如果节点在 主机组中,否则使用 default_vars)> default_vars