I'm ansibilizing a couple servers for a python application, some of which are CentOS, others are debian.
Is there a convenient way to locate a program that could be installed in various places, without resorting to the example below, and without repeating the same command several times (with different when:
clauses)?
For example, on CentOS it's /sbin/nologin
, on debian it's /usr/sbin/nologin
.
I have been trying to find and register the path in a variable, but it seems silly:
- name: Find nologin
command: ls -1 /usr/sbin/nologin
ignore_errors: yes
register: nologin_command
- name: Find nologin
command: ls -1 /sbin/nologin
register: nologin_command
when: nologin_command.stdout == ""
# nologin_command.stdout will be the path to one or the other
In my particular case, I'm actually trying to find the correct virtualenv_command
for the pip module. I have to be specific or I'll get the wrong one (i.e., for Python 2) or a path that doesn't exist.
My systems will have one of pyvenv, pyvenv-3.4, virtualenv, or virtualenv-3.4. At least one will be present, but, depending on the operating system and how python was installed, they are in different places or don't exist at all.