32

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?

Michal
  • 6,411
  • 6
  • 32
  • 45

1 Answers1

63

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

- hosts: sites
  user: root
  tags:
    - configuration
  gather_facts: no
  tasks:
    - setup:
    (...)
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
  • Dirty workaround but since there is no better way do that I will accept that as an answer. Thx – Michal Aug 18 '16 at 11:27
  • great workaround. Actually adding the `setup` task in `pre_task` didn't work for roles based deployment. if that works, it would be awesomatic to manage the gather_facts from main.yml – S.K. Venkat Dec 01 '18 at 14:27