variable access in a template being looped using with_items

30 views
Skip to first unread message

Torsten Reinhard

unread,
Dec 17, 2014, 10:47:17 AM12/17/14
to ansible...@googlegroups.com
 Hi,

I have a playbook like:

---
...
  vars_files
:
   
- vars/stage-{{stage}}.yml
   
- vars/extint/stage-{{stage}}.yml

  roles
:
   
- { role: extint, params: "{{ extint_instance }}" }
...



Inside the role "extint" I have this task, processing a template in a loop

...
- name: create generate {{env_name}}/env.properties
 
template: src=./env.properties.j2 dest=/path/to/config_generated/system/{{env_name}}{{ item.index }}/env.properties
  with_items
: params
  tags
: generate_resources
...


Now my problem is that all (global) variables that are read from the playbook ( -vars/extint/stage-{{stage}}.yml ) are not accessible in the template.

How can I loop over a list of items, process a template for each item - and access common variables in the template ? Do I need to pass the ansible_managed variables explicitely to the template somehow ?

Thanx, Torsten

Torsten Reinhard

unread,
Dec 17, 2014, 11:07:13 AM12/17/14
to ansible...@googlegroups.com
I forgot to mention I´m using Ansible 1.6.6.

solved it now after cleaning my eyes:-)

Variables can be accessed within the template - if the spelling of the variable is correct. I missed one character in a very_long_variable_name_with_some_underscores - and that causes the problem.
It 1st looked like the variable isn´t properly passed to the template.

Sorry for that,

Torsten
Reply all
Reply to author
Forward
0 new messages