@ -6,150 +6,153 @@
any_errors_fatal : true
any_errors_fatal : true
gather_facts : true
gather_facts : true
tasks:
tasks:
- name : ensure we can override ansible_python_interpreter
- name : can only run these tests on ansible >= 2.8.0
vars:
ansible_python_interpreter : overriddenpython
assert:
that:
- ansible_python_interpreter == 'overriddenpython'
fail_msg : "'ansible_python_interpreter' appears to be set at a high precedence to {{ ansible_python_interpreter }},
which breaks this test."
- name : snag some facts to validate for later
set_fact:
distro : '{{ ansible_distribution | default("unknown") | lower }}'
distro_version : '{{ ansible_distribution_version | default("unknown") }}'
os_family : '{{ ansible_os_family | default("unknown") }}'
- name : test that python discovery is working and that fact persistence makes it only run once
block:
block:
- name : clear facts to force interpreter discovery to run
- name : ensure we can override ansible_python_interpreter
meta : clear_facts
vars:
ansible_python_interpreter : overriddenpython
- name : trigger discovery with auto
assert:
vars:
that:
ansible_python_interpreter : auto
- ansible_python_interpreter == 'overriddenpython'
ping:
fail_msg : "'ansible_python_interpreter' appears to be set at a high precedence to {{ ansible_python_interpreter }},
register : auto_out
which breaks this test."
- name : get the interpreter being used on the target to execute modules
- name : snag some facts to validate for later
vars:
set_fact:
ansible_python_interpreter : auto
distro : '{{ ansible_distribution | default("unknown") | lower }}'
test_echo_module:
distro_version : '{{ ansible_distribution_version | default("unknown") }}'
register : echoout
os_family : '{{ ansible_os_family | default("unknown") }}'
# can't test this assertion:
- name : test that python discovery is working and that fact persistence makes it only run once
# - echoout.ansible_facts is not defined or echoout.ansible_facts.discovered_interpreter_python is not defined
block:
# because Mitogen's ansible_python_interpreter is a connection-layer configurable that
- name : clear facts to force interpreter discovery to run
# "must be extracted during each task execution to form the complete connection-layer configuration".
meta : clear_facts
# Discovery won't be reran though; the ansible_python_interpreter is read from the cache if already discovered
- assert:
- name : trigger discovery with auto
that:
vars:
- auto_out.ansible_facts.discovered_interpreter_python is defined
ansible_python_interpreter : auto
- echoout.running_python_interpreter == auto_out.ansible_facts.discovered_interpreter_python
ping:
register : auto_out
- name : test that auto_legacy gives a dep warning when /usr/bin/python present but != auto result
- name : get the interpreter being used on the target to execute modules
block:
vars:
- name : clear facts to force interpreter discovery to run
ansible_python_interpreter : auto
meta : clear_facts
test_echo_module:
register : echoout
- name : trigger discovery with auto_legacy
vars:
# can't test this assertion:
ansible_python_interpreter : auto_legacy
# - echoout.ansible_facts is not defined or echoout.ansible_facts.discovered_interpreter_python is not defined
ping:
# because Mitogen's ansible_python_interpreter is a connection-layer configurable that
register : legacy
# "must be extracted during each task execution to form the complete connection-layer configuration".
# Discovery won't be reran though; the ansible_python_interpreter is read from the cache if already discovered
- name : check for dep warning (only on platforms where auto result is not /usr/bin/python and legacy is)
- assert:
assert:
that:
that:
- auto_out.ansible_facts.discovered_interpreter_python is defined
- legacy.deprecations | default([]) | length > 0
- echoout.running_python_interpreter == auto_out.ansible_facts.discovered_interpreter_python
# only check for a dep warning if legacy returned /usr/bin/python and auto didn't
when : legacy.ansible_facts.discovered_interpreter_python == '/usr/bin/python' and
auto_out.ansible_facts.discovered_interpreter_python != '/usr/bin/python'
- name : test that auto_legacy gives a dep warning when /usr/bin/python present but != auto result
block:
- name : clear facts to force interpreter discovery to run
- name : test that auto_silent never warns and got the same answer as auto
meta : clear_facts
block:
- name : clear facts to force interpreter discovery to run
- name : trigger discovery with auto_legacy
meta : clear_facts
vars:
ansible_python_interpreter : auto_legacy
- name : initial task to trigger discovery
ping:
vars:
register : legacy
ansible_python_interpreter : auto_silent
ping:
- name : check for dep warning (only on platforms where auto result is not /usr/bin/python and legacy is)
register : auto_silent_out
assert:
that:
- assert:
- legacy.deprecations | default([]) | length > 0
that:
# only check for a dep warning if legacy returned /usr/bin/python and auto didn't
- auto_silent_out.warnings is not defined
when : legacy.ansible_facts.discovered_interpreter_python == '/usr/bin/python' and
- auto_silent_out.ansible_facts.discovered_interpreter_python == auto_out.ansible_facts.discovered_interpreter_python
auto_out.ansible_facts.discovered_interpreter_python != '/usr/bin/python'
- name : test that auto_legacy_silent never warns and got the same answer as auto_legacy
- name : test that auto_silent never warns and got the same answer as auto
block:
block:
- name : clear facts to force interpreter discovery to run
- name : clear facts to force interpreter discovery to run
meta : clear_facts
meta : clear_facts
- name : trigger discovery with auto_legacy_silent
- name : initial task to trigger discovery
vars:
vars:
ansible_python_interpreter : auto_legacy_silent
ansible_python_interpreter : auto_silent
ping:
ping:
register : legacy_silent
register : auto_silent_out
- assert:
- assert:
that:
that:
- legacy_silent.warnings is not defined
- auto_silent_out.warnings is not defined
- legacy_silent.ansible_facts.discovered_interpreter_python == legacy.ansible_facts.discovered_interpreter_python
- auto_silent_out.ansible_facts.discovered_interpreter_python == auto_out.ansible_facts.discovered_interpreter_python
- name : ensure modules can't set discovered_interpreter_X or ansible_X_interpreter
block:
- name : test that auto_legacy_silent never warns and got the same answer as auto_legacy
- test_echo_module:
block:
facts:
- name : clear facts to force interpreter discovery to run
ansible_discovered_interpreter_bogus : from module
meta : clear_facts
discovered_interpreter_bogus : from_module
ansible_bogus_interpreter : from_module
- name : trigger discovery with auto_legacy_silent
test_fact : from_module
vars:
register : echoout
ansible_python_interpreter : auto_legacy_silent
ping:
- assert:
register : legacy_silent
that:
- test_fact == 'from_module'
- assert:
- discovered_interpreter_bogus | default('nope') == 'nope'
that:
- ansible_bogus_interpreter | default('nope') == 'nope'
- legacy_silent.warnings is not defined
# this one will exist in facts, but with its prefix removed
- legacy_silent.ansible_facts.discovered_interpreter_python == legacy.ansible_facts.discovered_interpreter_python
- ansible_facts['ansible_bogus_interpreter'] | default('nope') == 'nope'
- ansible_facts['discovered_interpreter_bogus'] | default('nope') == 'nope'
- name : ensure modules can't set discovered_interpreter_X or ansible_X_interpreter
block:
- name : fedora assertions
- test_echo_module:
assert:
facts:
that:
ansible_discovered_interpreter_bogus : from module
- auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python3'
discovered_interpreter_bogus : from_module
when : distro == 'fedora' and distro_version is version('23', '>=')
ansible_bogus_interpreter : from_module
test_fact : from_module
- name : rhel assertions
register : echoout
assert:
that:
- assert:
# rhel 6/7
that:
- (auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python' and distro_version is version('8','<')) or distro_version is version('8','>=')
- test_fact == 'from_module'
# rhel 8+
- discovered_interpreter_bogus | default('nope') == 'nope'
- (auto_out.ansible_facts.discovered_interpreter_python == '/usr/libexec/platform-python' and distro_version is version('8','>=')) or distro_version is version('8','<')
- ansible_bogus_interpreter | default('nope') == 'nope'
when : distro in ('redhat', 'centos')
# this one will exist in facts, but with its prefix removed
- ansible_facts['ansible_bogus_interpreter'] | default('nope') == 'nope'
- name : ubuntu assertions
- ansible_facts['discovered_interpreter_bogus'] | default('nope') == 'nope'
assert:
that:
- name : fedora assertions
# ubuntu < 16
assert:
- (auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python' and distro_version is version('16.04','<')) or distro_version is version('16.04','>=')
that:
# ubuntu >= 16
- auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python3'
- (auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python3' and distro_version is version('16.04','>=')) or distro_version is version('16.04','<')
when : distro == 'fedora' and distro_version is version('23', '>=')
when : distro == 'ubuntu'
- name : rhel assertions
- name : mac assertions
assert:
assert:
that:
that:
# rhel 6/7
- auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python'
- (auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python' and distro_version is version('8','<')) or distro_version is version('8','>=')
when : os_family == 'Darwin'
# rhel 8+
- (auto_out.ansible_facts.discovered_interpreter_python == '/usr/libexec/platform-python' and distro_version is version('8','>=')) or distro_version is version('8','<')
always:
when : distro in ('redhat', 'centos')
- meta : clear_facts
- name : ubuntu assertions
assert:
that:
# ubuntu < 16
- (auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python' and distro_version is version('16.04','<')) or distro_version is version('16.04','>=')
# ubuntu >= 16
- (auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python3' and distro_version is version('16.04','>=')) or distro_version is version('16.04','<')
when : distro == 'ubuntu'
- name : mac assertions
assert:
that:
- auto_out.ansible_facts.discovered_interpreter_python == '/usr/bin/python'
when : os_family == 'Darwin'
always:
- meta : clear_facts
when : ansible_version.full is version('2.8.0', '>=')