Thanks Tom. It worked pefrect.
But I faced another issue with including tasks.
I have the file tasks.yml with two tasks, I tagged them as below:
- name: Perform action - FULL
shell: run_script_full.py
tags:
- full
- name: Perform action - BASIC
shell: run_script_basic.py
tags:
- basic
In my main playbook I want to inlcude them like below:
- hosts: controller
user: ansuser
tasks:
- include: tasks.yml tags=full
when: "'{{ LEVEL }}' == 'full'"
- include: tasks.yml tags=basic
when: "'{{ LEVEL }}' == 'basic'"
I run ansible with command:
ansible-playbook main_playbook.yml --extra-vars="LEVEL=basic". My point is
to execute only task with tagged as "basic" so I'd like main script to:
1) skip first include statement
2) execute tasks.yml in second include statement but only second one (first
is tagged as full so requirenments are not met).
Is it possible to achive this 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/8d4e1e93-c4f1-48ea-af38-41664642b68e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.