I'm not sure if it's the best way, but when including roles I'll do
something like:
- name: Include Some Role if Necessary
include_role:
name: some_role
when: SOME_ROLE_RUN is not defined
Then as the last task in "some_role" I'll have a task like this:
- set_fact:
SOME_ROLE_RUN: True
--Steve
On Fri, May 3, 2019 at 3:58 AM Bleacks <[email protected]> wrote:
> Hello everyone,
>
> (this is my first post BTW, I'll try to be as clear as possible)
>
> I want to include roles dynamically using this bit of code in my
> `playbook.yml` :
>
> tasks:
> - name: "Including roles dynamically"
> remote_user: "{{ target_user }}"
> include_role:
> name: "{{ item }}"
> with_items: "{{ roles_to_install | unique }}"
>
> I have roles like following:
> common
> role1 -> common
> role2 -> role1
>
> My goal is to always include every role (but I also have another use case
> where I want to specify which roles will be included).
>
> And using this method, if I try with roles_to_install = ['role1', 'role2']
> These roles will be included :
> - role 2 : 1 time
> - role 1 : 2 times
> - common : 3 times
>
> I searched through issues posted on git repo, I found some which may seem
> duplicates for me, but no solution was provided. (24326
> <https://github.com/ansible/ansible/issues/24326>, 47374
> <https://github.com/ansible/ansible/issues/47374> ).
>
> ansible --version: 2.7.10
>
> I also tried with `allow_duplicates: no` but the problem is not related to
> role inclusion, but to the dependency inclusion.
>
> Do you have an idea of what I could have forgotten? Maybe there is another
> way of treating the problem?
>
> Thank you for your time,
> If you need information I forgot, I'll be glad to add them
>
> --
> 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/5c1f6fff-5284-45a0-8d42-20a5d477a2be%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/5c1f6fff-5284-45a0-8d42-20a5d477a2be%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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/CAFbiokfMSm_AQgVuNnSphQk1BYz%2BEy4yhGD_egatOujo-w%2Bc5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.