I see, that worked fine, thanks.
On Wednesday, March 26, 2014 1:29:21 PM UTC, Matt Martz wrote:
>
> I think what you want, is to use the 'default' filter.
>
> Such as:
>
> template: src={{ item.name }}.j2 dest="/etc/config/{{
> item['target_name']|default(item.name) }}"
> with_items: configs
>
> I also changed target_name to not use dot notation, as that can sometimes
> still create issues with the default filter. In the above case, if item
> does not have a 'target_name' key, it will default to 'item.name'.
> --
> Matt Martz
> [email protected] <javascript:>
>
> On March 26, 2014 at 5:41:13 AM, Michael Mahemoff
> ([email protected]<javascript:>)
> wrote:
>
> I thought of a workaround, but also doesn't work:
>
> - set_fact: item.target_name = item.name
> when: item.target_name is not defined
> with_items: configs
>
> This way I could just always use item.target_name. It runs on the correct
> items, but seems that set_fact doesn't work as I expected for an item dict,
> as item.target_name is still undefined on the next task.
>
> On Wednesday, March 26, 2014 10:24:24 AM UTC, Michael Mahemoff wrote:
>>
>> I have a line like this, where "configs" variable is defined as a list of
>> dicts/hashes:
>>
>> template: src={{ item.name }}.j2 dest="/etc/config/{{ item.target_name|
>> item.name }}"
>> with_items: configs
>>
>> It basically allows the generated filename to be customised, but fall
>> back to the template name if none is provided. The problem is it doesn't
>> work, the generated filename is literally {{ item.target_name|item.name}}.
>> But it works fine without the default syntax (ie just {{
>> item.name }}). Is that expected behaviour and is there any workaround?
>>
> --
> 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] <javascript:>.
> To post to this group, send email to [email protected]<javascript:>
> .
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/9b56f7fb-457c-4e7e-a278-6e752a26a2da%40googlegroups.com<https://groups.google.com/d/msgid/ansible-project/9b56f7fb-457c-4e7e-a278-6e752a26a2da%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
--
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/3c94273c-cb14-49eb-a85e-6bc5bda5adf7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.