Can ternary() be used with vars or static strings only?

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'

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) }}”

Matt Martz:

(ansible_pkg_mgr != 'apt')| ternary(tor_user,
'_tor-' ~ item[0] ~ '_' ~ item.1.orport)

thanks, works!