That error occurs because roles were not really designed to be included
dynamically like that, so the value is not run through the template engine.
This is similar to the problem of using includes + with_* loops in v1,
where the variables could come from an inventory source, which would lead
to errors or unexpected behavior, as inventory sources are not available at
the time the roles are parsed/loaded.

I would recommend using Oswaldo's method, where available, or simple create
more specific playbooks depending on your situation.

James Cammarata
Director, Ansible Core Engineering
github: jimi-c

On Mon, Mar 30, 2015 at 10:35 AM, O. T. Suarez <[email protected]> wrote:

> Hi Rob,
>
>
> On Sun, Mar 29, 2015 at 8:33 PM, Rob White <[email protected]> wrote:
>
>> Hmmm, this doesn't seem to work for the roles parameter.
>>
>> I tried the following command:
>>
>> ansible-playbook test.yml -i inventories/local -e
>> '{"roles_to_deploy":["role1","role2"]}'
>>
>> The test.yml playbook just had:
>>
>> tasks:
>>     - name: Debug
>>       debug: msg="{{ item }}"
>>       with_items:
>>         "{{ roles_to_deploy }}"
>>
>> All good.
>>
>> I then tried the same command with my original playbook which has:
>>
>> roles:
>>     "{{ roles_to_deploy }}"
>>
>>
> Couldn't find a way to make it work that way.
> Here's an alternative:
>
>
>   roles:
>    - { role: role1, when 'role1' in roles_to_deploy}
>    - { role: role2, when 'role2' in roles_to_deploy}
>
> It might seems too much work to edit the playbook file each time you add a
> new role, but it's just a single line and when comparing the number of
> times you'll be executing that playbook file against the number of edits,
> it should worth the shot.
>
> Regards,
> Osvaldo
>
> --
> 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/CAJZu1hX8rwGkGTO1xK9%3D90P3DNuk-1SZB_65u6oPz4ow%3D-AzOA%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAJZu1hX8rwGkGTO1xK9%3D90P3DNuk-1SZB_65u6oPz4ow%3D-AzOA%40mail.gmail.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/CAMFyvFh5WyJdhioD%2BQrZqrS2E7y%3DkYc45oNhgCVvSKqS%2BGwL%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to