简体   繁体   中英

Ansible - prevent gathering facts for hosts that are not used

I have a playbook.yml along the lines:

- name: Play1
  hosts: vm1
  ...
  tags: pl1

- name: Play2
  hosts: vm2
  ...
  tags: pl2

Now imagine scenario, that vm1 is dead and I don't care about it for the time being and I want to run only the 2nd play like this:

ansible-playbook playbook.yml --tags=pl2

But now, Ansible fails with the error when gathering facts for vm1 . Is there a way to instruct Ansible to be smarter and ignore other plays completely? And why does it even do that?

If you really think that's the best way to manage your servers...

Use gather_facts: false and add explicitly a setup task:

- name: Play1
  gather_facts: no
  hosts: vm1
  pre_tasks:
    - setup:
  ...
  tags: pl1

I think what you're looking for is the --limit option, which only runs tasks on the specified host(s) and/or group(s).

ansible-playbook playbook.yml --limit=vm2

https://docs.ansible.com/ansible/2.9/user_guide/intro_patterns.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM