1、setup 从远程机器上获取facts
gather_subset参数默认是all,定义收集信息的范围。可能参数有all, min, hardware, network, virtual, ohai, and facter
#ansible all -m setup -a 'gather_subset=!all,!any,facter'
- name: Collect only facts returned by facter
setup:
gather_subset:
- '!all'
- '!any'
- facter
2、默认使用setup模块来获取远程主机信息
- hosts: web
gather_facts: True
gather_subset: network
- hosts: web
gather_facts: True
gather_subset: network,virtual
总结:平时使用二者没有多大区别(个人结论)
参考文章:
https://medium.com/@abhijeet.kamble619/10-things-you-should-start-using-in-your-ansible-playbook-808daff76b65
https://docs.ansible.com/ansible/devel/modules/gather_facts_module.html