Force fact-gathering on all hosts

前端 未结 4 1846
夕颜
夕颜 2020-12-15 17:04

I\'m sitting in front of a fairly complex Ansible project that we\'re using to set up our local development environments (multiple VMs) and there\'s one role that uses the f

4条回答
  •  清酒与你
    2020-12-15 17:46

    In general the way to get facts for all hosts even when you don't want to run tasks on all hosts is to do something like this:

    - hosts: all
      tasks: [ ]  
    

    But as you mentioned, the --limit parameter will limit what hosts this would be applied to.

    I don't think there's a way to simply tell Ansible to ignore the --limit parameter on any plays. However there may be another way to do what you want entirely within Ansible.

    I haven't used it personally, but as of Ansible 1.8 fact caching is available. In a nutshell, with fact caching enabled Ansible will use a redis server to cache all the facts about hosts it encounters and you'll be able to reference them in subsequent playbooks:

    With fact caching enabled, it is possible for machine in one group to reference variables about machines in the other group, despite the fact that they have not been communicated with in the current execution of /usr/bin/ansible-playbook.

提交回复
热议问题