Make the python3 fact module compatible with python2 for EL7 boxes
Signed-off-by: Aurélien Bompard <aurelien@bompard.org>
This commit is contained in:
parent
ffbc4a001c
commit
bf24d014bd
2 changed files with 13 additions and 8 deletions
|
@ -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
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
@ -48,14 +48,19 @@ sitelib:
|
||||||
|
|
||||||
|
|
||||||
def run_module():
|
def run_module():
|
||||||
result = {
|
|
||||||
"sitelib": get_python_lib(),
|
|
||||||
}
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec={},
|
argument_spec={},
|
||||||
supports_check_mode=True
|
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():
|
def main():
|
||||||
|
|
|
@ -332,8 +332,8 @@ vars_plugins={{ ansible_base }}/ansible/vars_plugins:~/.ansible/plugins/vars:/us
|
||||||
;error_on_missing_handler=True
|
;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.
|
# (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
|
||||||
;facts_modules=smart, python3_fact
|
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
|
# (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
|
;host_key_checking=True
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue