Yes, I have that stuff in my group_vars/all and in various vars.yml files. 
There no special magic to it except that you have to enable the do 
extension in ansible.cfg.

Every string variable in Ansible is fed through the templating engine:

---

foobar_config_path: "/etc/foobar"

foobar_foomatic_file: "{{ foobar_config_path }}/foomatic.conf"

greeting: "Hello {% for host in groups['all'] %}{{ host }}, {% endfor %} 
and everybody else!"

block_string: |
  This is just a convenient YAML way for assigning multi-line strings to a 
variable,
  possibly with {{ 'splendid' if datacenter_location == 'UK' else 'awesome' 
}} magic
  embedded in it...





On Wednesday, May 20, 2015 at 8:55:20 PM UTC+2, Javeria Khan wrote:
>
> Thanks guys, 
>
> Christian is your solution doable in a regular yml? I thought jinja 
> constructs were only allowed in jinja templates? What I have is a regular 
> .yml that defines all my variables.
>
> Shawn I believe your solution requires creating a task to loop over 
> my_dict, I prefer to do it outside of the playbook.
>
>
>
>
> On Wednesday, 20 May 2015 11:37:26 UTC-7, Shawn Ferry wrote:
>>
>> Why not something like this?
>>
>> do_something_with: item.name
>> with_items: your_dict
>> when: item.item_en == True
>>
>>
>> On Wednesday, May 20, 2015 at 8:41:00 AM UTC-4, Javeria Khan wrote:
>>>
>>> Hi,
>>>
>>> I've tried searching everything but can't find a possible solution. I 
>>> have a yml that defines all my variables for a playbook and I need to do 
>>> something like the following inside of it:
>>> ----------------
>>> my_dict:
>>>  - {  item_en: True,  name: name1, type:  type1,  key: value1 }
>>>  - {  item_en: False, name: name2, type:  type2,  key: value2 }
>>>  - {  item_en: True,  name: name3, type:  type3,  key: value3 }
>>>
>>> my_list:
>>> {%  for item in my_dict %}
>>> {% if my_dict[item].item_en == True %}
>>>     {{ my_dict[item].name  }}
>>> {% endfor %}
>>> ---------------
>>>
>>> So basically I need 'my_list' to be a list of 'names' from every dict 
>>> object that has item_en = True. Based on the data structure above, it would 
>>> look like this:
>>>
>>> my_list:
>>>  - name1
>>>  - name3
>>>
>>> I know this is possible using the jinja loop syntax in a template but 
>>> this isn't a template file.
>>>
>>> Thanks 
>>>
>>

-- 
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/b9316bd0-99a3-4547-ac03-535414e88d03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to