Several of my playbooks have sub-plays structure like this:
- hosts: sites user: root tags: - configuration tasks: (...) - hosts: sites user: root tags: - db tasks: (...) - hosts: sites user: "{{ site_vars.user }}" tags: - app tasks: (...)
In Ansible 1.x both admins and developers were able to use such playbook. Admins could run it with all the tags (root and user access), while developers had access only to the last tag with tasks at user access level. When developers run this playbook with the app tag, gathering facts was skipped for the first two tags. Now however, in Ansible 2.1, it is not being skipped, which causes failure for users without root access.
Is there a mechanism or an easy modification to fix this behaviour? Is there a new approach which should be applied for such cases now?
You can use gather_facts: no keyword in your playbook. It will disable this task automatically.
The gather_facts module from the Ansible playbook runs the setup module by default at the start of each playbook to gather the facts about remote hosts. Fetch the Ansible facts and display them using a playbook. Fetching the Ansible facts, filtering them, and displaying them using a playbook.
When Ansible receives a non-zero return code from a command or a failure from a module, by default it stops executing on that host and continues on other hosts. However, in some circumstances you may want different behavior. Sometimes a non-zero return code indicates success.
If you want to run multiple tasks in a playbook concurrently, use async with poll set to 0. When you set poll: 0 , Ansible starts the task and immediately moves on to the next task without waiting for a result. Each async task runs until it either completes, fails or times out (runs longer than its async value).
There is an easy mod – turn off facts gathering and call setup
explicitly:
- hosts: sites user: root tags: - configuration gather_facts: no tasks: - setup: (...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With