You cannot nest {{ }}. You can think of anything inside of {{ }} as a code
block, so you just use bare variable names.
I think this should work:
owner="{{ (ansible_pkg_mgr != 'apt')| ternary(tor_user,
'_tor-' ~ item[0] ~ '_' ~ item.1.orport) }}"
On Sunday, January 17, 2016, nusenu <[email protected]> wrote:
> Hi,
>
> to avoid copying many tasks I was trying to use the ternary() filter as
> seen in
>
> https://groups.google.com/forum/#!msg/ansible-project/4bhkNQvrbhc/Vs3u8QQVCAAJ
>
> goal:
> If I'm on debian based systems I'd like the owner to be
> _tor-{{ item[0] }}_{{ item.1.orport }}
>
> on other systems it should just be
> {{ tor_user }}
>
> this is one example of a currently working tasks which I would like to
> condense into one by using the ternary() filter:
>
>
> - name: Ensure directory exists and is owned by tor_user
> file: path={{ tor_DataDir }}/{{ item[0] }}_{{ item.1.orport }}
> state=directory
> owner={{ tor_user }}
> with_nested:
> - "{{ tor_ips }}"
> - "{{ tor_ports }}"
> when: ansible_pkg_mgr != 'apt'
>
>
> - name: Ensure directory exists and is owned by tor_user
> file: path={{ tor_DataDir }}/{{ item[0] }}_{{ item.1.orport }}
> state=directory
> owner=_tor-{{ item[0] }}_{{ item.1.orport }}
> with_nested:
> - "{{ tor_ips }}"
> - "{{ tor_ports }}"
> when: ansible_pkg_mgr == 'apt'
>
> ==========================================
>
> attempt to use ternary:
>
> - name: Ensure Tor "keys" directory exists and is owned by tor_user
> file: path={{ tor_DataDir }}/{{ item[0] }}_{{ item.1.orport }}/keys
> state=directory
> owner="{{ (ansible_pkg_mgr != 'apt')| ternary('{{ tor_user }}',
> '_tor-{{ item[0] }}_{{ item.1.orport }}') }}"
> with_nested:
> - "{{ tor_ips }}"
> - "{{ tor_ports }}"
>
>
> Fails with:
>
> msg: chown failed: failed to look up user _tor-{# item[0] #}_{#
> item.1.orport #}
>
> so it tries to use it as a literal string.
>
> Is what I'm trying to achieve possible or should I simply stick with the
> duplicate tasks?
>
> 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] <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/569B6B3C.4030503%40openmailbox.org
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
Matt Martz
@sivel
sivel.net
--
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/CAD8N0v-2e4vE9Ps5x3ZgWJULjj55AUNPg5OB9%2B8tCH8h0AFEnQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.