Cheers Dan for your answer. 
It works but it's not exactly what I want to achieve. I tried one more 
configruation using tags but still doesn't work as I expect. 
I have main playbook (test1.yml) with only one include: 

- include: test2.yml tags="{{ TEST_LEVEL }}"

Playbook test2.yml looks like below: 

- hosts: controller
  user: ansuser
  tasks:
  - name: Test task 1
    shell: 'echo 1'
    tags:
      - test1

- hosts: controller
  user: ansuser
  tasks:
  - name: Test task 2
    shell: 'echo 2'
    tags:
      - test2

I'd like to run main playbook with extra-vars where I set TEST_LEVEL, like: 
*ansible-playbook examples/test1.yml --extra-vars="TEST_LEVEL=test2"*

and value of TEST_LEVEL to be a tag for choosing tasks from test2.yml 
playbook. 

For now it executes all tasks (whatever value for TEST_LEVEL I choose). Is 
there any typo/wrong quotas etc.in my playbook or I just try to use 
something wrong way? 

Regards,
Wojtek












W dniu wtorek, 13 stycznia 2015 09:29:08 UTC+1 użytkownik Wojciech Korzenny 
napisał:
>
> 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/1502eeb0-34f1-4c7d-bb7c-af37523fab88%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to