I am struggling to find a reasonable method to detect which of python-pip
or python3-pip
I should install depending on the contents of the ansible_python
fact. This is on Debian and Ubuntu.
Looking at ansible_python
contents, I did not see anything that would let me correlate the Python version Ansible uses with the package name used to install that Python version. So even though I could glean the path to the Python executable from the fact I don't see how to determine the package used to install it.
The rationale is trying to avoid hardcoding stuff into my playbook. But failing everything else I'd also be willing to hardcode these assumptions into my playbook. The "best" I've come up with so far was to use the package_facts
module to collect the information on installed packages, then use ansible_python.version.major
to pick from either python-pip
or python3-pip
, which still contains the assumptions: 1.) that ansible_python.version.major==2
maps to python-pip
and ansible_python.version.major==3
maps to python3-pip
and 2.) that ansible_python.executable
does name either of the packaged Python versions available in the python
and python3
packages respectively.
Is there an objectively better way? Better isn't meant to elicit opinions here, anything getting rid of the implied assumptions qualifies as objectively better.