Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable gathering facts for subplays not included within given tag

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?

like image 422
Michal Avatar asked Jul 11 '16 13:07

Michal


People also ask

How do you turn off Ansible gathering facts?

You can use gather_facts: no keyword in your playbook. It will disable this task automatically.

How do you gather Ansible facts?

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.

How can Error Handling be done in Ansible?

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.

How do I run a parallel task in Ansible?

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).


1 Answers

There is an easy mod – turn off facts gathering and call setup explicitly:

- hosts: sites   user: root   tags:     - configuration   gather_facts: no   tasks:     - setup:     (...) 
like image 188
Konstantin Suvorov Avatar answered Sep 26 '22 10:09

Konstantin Suvorov