Ansible 获取主机信息模块setup、获取文件详细信息模块stat(学习笔记十)

2022-05-24 16:46:51 浏览数 (1)

setup

1、获取setup的所有信息,获取的信息有上百条: ansible all -m setup "ansible_facts": { "ansible_all_ipv4_addresses": [ "172.xx.xx.xxx" ], "ansible_all_ipv6_addresses": [ "fe80::250:56ff:febc:5e1d" ], .......................................... .......................................... "module_setup": true }, "changed": false }

2、对查询的结果进行筛选: ansible all -m setup -a 'filter=ansible_*_mb'

image.png

3、将每台主机的信息,分别存放到特定目录中,文件名为hosts文件中对应的别名或IP: ansible all -m setup --tree /tmp/facts

image.png

stat

4、获取文件的详细信息: ansible all -m stat -a "path=/root/test.sh"

image.png

0 人点赞