Using jinja in group_vars with variables passed by --extra-vars

1,499 views
Skip to first unread message

Wojciech Korzenny

unread,
Jan 19, 2015, 10:50:46 AM1/19/15
to ansible...@googlegroups.com
Hi,

I'm trying to use jinja for setting test_plan parameter in group_vars based on some variables passed by --extra-vars.

This is my group_vars/load_drivers content:
--

{% if ENVIRONMENT_SPLIT == single %}

  test_plan: '{{ load_driver_dir }}/{{ ENVIRONMENT_SPLIT }}_{{ TEST_STACK_1 }}_soak_test_plan.jmx'

{% elif "'{{ ENVIRONMENT_SPLIT }}' == 'multi'" and "'{{ TEST_STACK_2 }}' != 'None'" and "'{{ TEST_STACK_1 }}' != '{{ TEST_STACK_2 }}'" %}

  test_plan: '{{ load_driver_dir }}/{{ ENVIRONMENT_SPLIT }}_{{ TEST_STACK_1 }}_{{ TEST_STACK_2 }}_soak_test_plan.jmx'

{% elif "'{{ ENVIRONMENT_SPLIT }}' == 'multi'" and "'{{ TEST_STACK_2 }}' == 'None'" %}

  test_plan: '{{ load_driver_dir }}/{{ ENVIRONMENT_SPLIT }}_{{ TEST_STACK_1 }}_{{ TEST_STACK_1 }}_soak_test_plan.jmx'

{% endif %}



I execute main playbook:
ansible-playbook main.yml --extra-vars="ENVIRONMENT_SPLIT='single' TEST_STACK_1='comm1' TEST_STACK_2='comm1'"

but unfortunately I get error message:

{% if ENVIRONMENT_SPLIT == single %}
  test_plan: '{{ load_driver_dir }}/{{ ENVIRONMENT_SPLIT }}_{{ TEST_STACK_1 }}_soak_test_plan.jmx'
           ^
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 }}"      


[SSH] exit-status: 1
Finished: FAILURE


I tried to use different quotas in different places but same results every time.
Can you help me with this issue?

W.

Brian Coca

unread,
Jan 19, 2015, 11:15:57 AM1/19/15
to ansible...@googlegroups.com
group vars are not parsed by jinja2 only yaml, you can use jinja in
the values if they will later get evaluated in the playbook, but the
file itself does not pass through jinja.


--
Brian Coca
Reply all
Reply to author
Forward
0 new messages