I have a playbook with the interpreter (ansible_python_interpreter) set manually.
Then I have 2 tasks (foo, bar) as an example.
I only want bar executed if the interpreter is set to python2. How can I make that happen?
hosts: "{{ ansible_limit | default (omit) }}"
vars:
ansible_python_interpreter: "/usr/bin/python3"
tasks:
- name: foo
shell: /home/test/foo
- name: bar
shell: /home/test/bar
I tried when but did not get the access to the variable right I think.
when: ansible_python_interpreter.find('python2') != -1
The setup module provides you with the option to gather python_version
gives for example,
Then, test the version. For example,
gives
Example of a complete playbook for testing