Hi Wojtek

The error you are getting is due to inconsistent quoting. You may also need
to cast your variable. Try one of these:

- include: some_playbook.yml
  when: "{{ some_variable | bool }} == True"

or shorter:

- include: some_playbook.yml
  when: "{{ some_variable | bool }}"

See http://docs.ansible.com/YAMLSyntax.html#gotchas and
http://docs.ansible.com/playbooks_variables.html#other-useful-filters for
more details.

Regards
Tom


On 13 January 2015 at 10:29, Wojciech Korzenny <[email protected]> wrote:

Hi,
>
> I want to use variable in when statement, for example:
>
> - include: some_playbook.yml
>   when: "{{ SOME_VARIABLE }}" == "true"
>
> where:
> SOME_VARIABLE - is given as false/true via --extra-vars
>
> Unfortunately I get error:
>
> ERROR: Syntax Error while loading YAML script, run_soak_test.yaml
> Note: The error may actually appear before this position: line 3, column 26
>
> - include: some_playbook.yml
>   when: "{{ SOME_VARIABLE }}" == "true"
>                          ^
> We could be wrong, but this one looks like it might be an issue with
> missing quotes.  Always quote template expression brackets when they
> start a value. For instance:
>
>     with_items:
>       - {{ foo }}
>
> Should be written as:
>
>     with_items:
>       - "{{ foo }}"
>
>
> Do you know what's the reason and what's the workaround?
>
> Thanks in advance,
> Wojtek
>
> --
> 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/4cb1d171-cd47-44dc-ae97-87bc7b2dc5a1%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/4cb1d171-cd47-44dc-ae97-87bc7b2dc5a1%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/CAAnNz0P%2BxYfMhPVNNNxFKd1vhLuYtrUN2i5WVudWT_%3DqqCs8Ww%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to