diff --git a/library/python3_fact.py b/library/python3_fact.py index ca5b7a4aaf..507398f29d 100644 --- a/library/python3_fact.py +++ b/library/python3_fact.py @@ -1,6 +1,6 @@ -#!/usr/bin/env python3 +#!/usr/bin/env python -from distutils.sysconfig import get_python_lib +from subprocess import check_output from ansible.module_utils.basic import AnsibleModule @@ -48,14 +48,19 @@ sitelib: def run_module(): - result = { - "sitelib": get_python_lib(), - } module = AnsibleModule( argument_spec={}, supports_check_mode=True ) - module.exit_json(changed=False, ansible_facts=dict(python3=result)) + try: + output = check_output([ + "python3", "-c", + "from distutils.sysconfig import get_python_lib; print(get_python_lib())", + ]) + except OSError: + module.exit_json(changed=False, ansible_facts=dict()) + else: + module.exit_json(changed=False, ansible_facts=dict(python3=output.strip())) def main(): diff --git a/roles/ansible-server/templates/ansible.cfg.j2 b/roles/ansible-server/templates/ansible.cfg.j2 index 4d5eff9414..19e02cba96 100644 --- a/roles/ansible-server/templates/ansible.cfg.j2 +++ b/roles/ansible-server/templates/ansible.cfg.j2 @@ -332,8 +332,8 @@ vars_plugins={{ ansible_base }}/ansible/vars_plugins:~/.ansible/plugins/vars:/us ;error_on_missing_handler=True # (list) Which modules to run during a play's fact gathering stage, using the default of 'smart' will try to figure it out based on connection type. -facts_modules=smart -;facts_modules=smart, python3_fact +;facts_modules=smart +facts_modules=smart, python3_fact # (boolean) Set this to "False" if you want to avoid host key checking by the underlying tools Ansible uses to connect to the host ;host_key_checking=True