Hi,
I'm seeing the same problem and have a very similar use case.
allow_duplicates = yes doesn't seem to be working as I would expect. Unsure
if its a bug or I have misunderstood how it works
James
On Thursday, 27 November 2014 15:32:27 UTC, Robb Wagoner wrote:
>
> I'd like for roles which configure Node apps, to generate some snippets
> for an HAProxy config. I'd like to be able to call the same role dependency,*
> app_snippet*, in a generalized way, across many apps (app1, app2, etc.).
> However, the dependency executes once, even though I am using the
> *allow_duplicates:
> yes* in the *meta/main.yml* for each app.
>
> In short, I'd like role *app_snippet* to be completely data-driven and
> called as a dependency of each *app*, and executed once for each *app*,
> using *vars* from the calling *app* role.
>
> Am I missing something fundamental with Variable scoping? Or is this an
> anti-pattern in Ansible? The *allow_duplicates: yes* boolean seems to
> only be in the scope of the calling app role, not global across roles.
>
>
> PLAYBOOK: *apps.yml*
>
> - name: install apps
> hosts: webservers
> roles:
> - { role: app1 }
> - { role: app2 }
>
>
> ROLES:
> roles/app1/
> roles/app2/
> roles/app_snippet/
>
>
> ROLE appN: (i.e. app1 and app2 are mostly the same, for the purposes of
> role dependency)
>
> *roles/appN/vars/main.yml*
> ---
> app: appN
> install_dir: /opt/{{app}}
>
>
> *roles/appN/meta/main.yml*
> ---
> allow_duplicates: yes
> dependencies:
> - { role: app_snippet }
>
>
> *roles/app_snippet/tasks/main.yml*
> ---
> - name: HAProxy Backend Snippet {{app}}
> template: src=haproxy_backend.cfg.j2
> dest=/etc/haproxy/conf/backend.d/{{app}}.cfg
>
>
> I only see the task *app_snippet | HAProxy Backend Snippet app1* execute.
> I don't see it execute for *app2*.
>
> The same is true (runs once) if I assign a static parameter to the
> *app_snippet* role dependency for each app:
>
> *roles/app1/meta/main.yml*
> ---
> allow_duplicates: yes
> dependencies:
> - { role: app_snippet, app: app1 }
>
> *roles/app2/meta/main.yml*
> ---
> allow_duplicates: yes
> dependencies:
> - { role: app_snippet, app: app2 }
>
> This suggests that it is not a variable scoping issue. But it does suggest
> that late interpolation of variables causes the *app_snippet* tasks in
> both calls to be considered "the same", and subsequently executed once.
>
> Any help/pointers are appreciated! Thanks!
>
> Robb
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/4ad43fa0-cc4f-4098-bfe9-c2c5d352c5d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.