ansible 192.168.1.21-m setup 获取系统信息,类似于Saltstack的Grains
ansible all -m setup -a "filter=ansible_hostname" 过滤某一个值
在模板文件中这样引用Facts信息:
{{ ansible_devices.sda.model }} ansible_devices下的sda字典下key为model的值
{{ ansible_hostname }} ansible_hostname的值
---------------------------
自定义Facts
目标机器操作
mkdir -pv /etc/ansible/facts.d
cd /etc/ansible/facts.d
vim preferences.fact
[general]
max_memory_size=32
max_user_processes=3730
open_files=65535
执行 ansible 192.168.8.22 -m setup -a "filter=ansible_local"
.....
"ansible_facts": {
"ansible_local": {
"preferences": {
"general": {
"max_memory_size": "32",
"max_user_processes": "3730",
"open_files": "65535"
}
}
}
},
........