mirror of https://github.com/ansible/ansible.git
fix delegated interpreter discovery (#69604)
* fix delegated interpeter * allow returning fact if it is 'the right host' * added note for future fix/efficiency as it stands we rerun discovery for the delegated host unless its saving facts to itself * fixed test lacking delegate_to mockpull/69669/head
parent
dc63b36501
commit
de3f7c7739
@ -0,0 +1,3 @@
|
||||
bugfixes:
|
||||
- interpreter discovery will now use correct vars (from delegated host) when in delegate_to task.
|
||||
- discovery will NOT update incorrect host anymore when in delegate_to task.
|
@ -0,0 +1,5 @@
|
||||
testhost ansible_python_interpreter=firstpython
|
||||
testhost2 ansible_python_interpreter=secondpython
|
||||
|
||||
[all:vars]
|
||||
ansible_connection=local
|
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
__metaclass__ = type
|
||||
|
||||
import sys
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
def main():
|
||||
module = AnsibleModule(argument_spec={})
|
||||
module.exit_json(**dict(found=sys.executable))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
@ -0,0 +1,47 @@
|
||||
- name: ensure they are different
|
||||
hosts: localhost
|
||||
tasks:
|
||||
- name: dont game me
|
||||
assert:
|
||||
msg: 'expected different values but got ((hostvars["testhost"]["ansible_python_interpreter"]}} and {{hostvars["testhost2"]["ansible_python_interpreter"]}}'
|
||||
that:
|
||||
- hostvars["testhost"]["ansible_python_interpreter"] != hostvars["testhost2"]["ansible_python_interpreter"]
|
||||
|
||||
- name: no delegation
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: detect interpreter used by each host
|
||||
detect_interpreter:
|
||||
register: baseline
|
||||
|
||||
- name: verify it
|
||||
assert:
|
||||
msg: 'expected {{ansible_python_interpreter}} but got {{baseline.found|basename}}'
|
||||
that:
|
||||
- baseline.found|basename == ansible_python_interpreter
|
||||
|
||||
- name: actual test
|
||||
hosts: testhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: original host
|
||||
detect_interpreter:
|
||||
register: found
|
||||
|
||||
- name: verify it orig host
|
||||
assert:
|
||||
msg: 'expected {{ansible_python_interpreter}} but got {{found.found|basename}}'
|
||||
that:
|
||||
- found.found|basename == ansible_python_interpreter
|
||||
|
||||
- name: delegated host
|
||||
detect_interpreter:
|
||||
register: found2
|
||||
delegate_to: testhost2
|
||||
|
||||
- name: verify it delegated
|
||||
assert:
|
||||
msg: 'expected {{hostvars["testhost2"]["ansible_python_interpreter"]}} but got {{found2.found|basename}}'
|
||||
that:
|
||||
- found2.found|basename == hostvars["testhost2"]["ansible_python_interpreter"]
|
Loading…
Reference in New Issue