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].
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/569B6B3C.4030503%40openmailbox.org.
For more options, visit https://groups.google.com/d/optout.
signature.asc
Description: OpenPGP digital signature
