Force fact-gathering on all hosts

前端 未结 4 1845
夕颜
夕颜 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:48

    You could modify your playbook to:

    ...
    - hosts: "{{ limit_hosts|default('default_group') }}"
      tasks:
        ...
    ...
    

    And when you run it, if some_var is not defined (normal state) then it will run on the default_group inventory group, BUT if you run it as:

    ansible-playbook --extra-vars "limit_hosts=myHost" myplaybook.yml
    

    Then it will only run on your myHost, but you could still have other sections with different hosts: .. declarations, for fact gathering, or anything else actually.

提交回复
热议问题