mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
python_requirements_info - improvements (#3797)
* python_requirements_info - improvements - returns python version broken down into its components - minor refactoring * adjusted indentation in the documentaiton blocks * added changelog fragment * fixes from PR review + assertion in test
This commit is contained in:
parent
c6dcae5fda
commit
ff0c065ca2
3 changed files with 57 additions and 13 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- python_requirements_info - returns python version broken down into its components, and some minor refactoring (https://github.com/ansible-collections/community.general/pull/3797).
|
|
@ -10,8 +10,8 @@ DOCUMENTATION = '''
|
||||||
module: python_requirements_info
|
module: python_requirements_info
|
||||||
short_description: Show python path and assert dependency versions
|
short_description: Show python path and assert dependency versions
|
||||||
description:
|
description:
|
||||||
- Get info about available Python requirements on the target host, including listing required libraries and gathering versions.
|
- Get info about available Python requirements on the target host, including listing required libraries and gathering versions.
|
||||||
- This module was called C(python_requirements_facts) before Ansible 2.9. The usage did not change.
|
- This module was called C(python_requirements_facts) before Ansible 2.9. The usage did not change.
|
||||||
options:
|
options:
|
||||||
dependencies:
|
dependencies:
|
||||||
type: list
|
type: list
|
||||||
|
@ -21,9 +21,10 @@ options:
|
||||||
Supported operators: <, >, <=, >=, or ==. The bare module name like
|
Supported operators: <, >, <=, >=, or ==. The bare module name like
|
||||||
I(ansible), the module with a specific version like I(boto3==1.6.1), or a
|
I(ansible), the module with a specific version like I(boto3==1.6.1), or a
|
||||||
partial version like I(requests>2) are all valid specifications.
|
partial version like I(requests>2) are all valid specifications.
|
||||||
|
default: []
|
||||||
author:
|
author:
|
||||||
- Will Thames (@willthames)
|
- Will Thames (@willthames)
|
||||||
- Ryan Scott Brown (@ryansb)
|
- Ryan Scott Brown (@ryansb)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
|
@ -33,8 +34,8 @@ EXAMPLES = '''
|
||||||
- name: Check for modern boto3 and botocore versions
|
- name: Check for modern boto3 and botocore versions
|
||||||
community.general.python_requirements_info:
|
community.general.python_requirements_info:
|
||||||
dependencies:
|
dependencies:
|
||||||
- boto3>1.6
|
- boto3>1.6
|
||||||
- botocore<2
|
- botocore<2
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
@ -48,14 +49,44 @@ python_version:
|
||||||
returned: always
|
returned: always
|
||||||
type: str
|
type: str
|
||||||
sample: "2.7.15 (default, May 1 2018, 16:44:08)\n[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]"
|
sample: "2.7.15 (default, May 1 2018, 16:44:08)\n[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]"
|
||||||
|
python_version_info:
|
||||||
|
description: breakdown version of python
|
||||||
|
returned: always
|
||||||
|
type: dict
|
||||||
|
contains:
|
||||||
|
major:
|
||||||
|
description: The C(major) component of the python interpreter version.
|
||||||
|
returned: always
|
||||||
|
type: int
|
||||||
|
sample: 3
|
||||||
|
minor:
|
||||||
|
description: The C(minor) component of the python interpreter version.
|
||||||
|
returned: always
|
||||||
|
type: int
|
||||||
|
sample: 8
|
||||||
|
micro:
|
||||||
|
description: The C(micro) component of the python interpreter version.
|
||||||
|
returned: always
|
||||||
|
type: int
|
||||||
|
sample: 10
|
||||||
|
releaselevel:
|
||||||
|
description: The C(releaselevel) component of the python interpreter version.
|
||||||
|
returned: always
|
||||||
|
type: str
|
||||||
|
sample: final
|
||||||
|
serial:
|
||||||
|
description: The C(serial) component of the python interpreter version.
|
||||||
|
returned: always
|
||||||
|
type: int
|
||||||
|
sample: 0
|
||||||
|
version_added: 4.2.0
|
||||||
python_system_path:
|
python_system_path:
|
||||||
description: List of paths python is looking for modules in
|
description: List of paths python is looking for modules in
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
sample:
|
sample:
|
||||||
- /usr/local/opt/python@2/site-packages/
|
- /usr/local/opt/python@2/site-packages/
|
||||||
- /usr/lib/python/site-packages/
|
- /usr/lib/python/site-packages/
|
||||||
- /usr/lib/python/site-packages/
|
|
||||||
valid:
|
valid:
|
||||||
description: A dictionary of dependencies that matched their desired versions. If no version was specified, then I(desired) will be null
|
description: A dictionary of dependencies that matched their desired versions. If no version was specified, then I(desired) will be null
|
||||||
returned: always
|
returned: always
|
||||||
|
@ -80,8 +111,8 @@ not_found:
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
sample:
|
sample:
|
||||||
- boto4
|
- boto4
|
||||||
- requests
|
- requests
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
@ -106,11 +137,19 @@ operations = {
|
||||||
'==': operator.eq,
|
'==': operator.eq,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
python_version_info = dict(
|
||||||
|
major=sys.version_info[0],
|
||||||
|
minor=sys.version_info[1],
|
||||||
|
micro=sys.version_info[2],
|
||||||
|
releaselevel=sys.version_info[3],
|
||||||
|
serial=sys.version_info[4],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
dependencies=dict(type='list', elements='str')
|
dependencies=dict(type='list', elements='str', default=[])
|
||||||
),
|
),
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
)
|
)
|
||||||
|
@ -119,6 +158,7 @@ def main():
|
||||||
msg='Could not import "distutils" and "pkg_resources" libraries to introspect python environment.',
|
msg='Could not import "distutils" and "pkg_resources" libraries to introspect python environment.',
|
||||||
python=sys.executable,
|
python=sys.executable,
|
||||||
python_version=sys.version,
|
python_version=sys.version,
|
||||||
|
python_version_info=python_version_info,
|
||||||
python_system_path=sys.path,
|
python_system_path=sys.path,
|
||||||
)
|
)
|
||||||
pkg_dep_re = re.compile(r'(^[a-zA-Z][a-zA-Z0-9_-]+)(?:(==|[><]=?)([0-9.]+))?$')
|
pkg_dep_re = re.compile(r'(^[a-zA-Z][a-zA-Z0-9_-]+)(?:(==|[><]=?)([0-9.]+))?$')
|
||||||
|
@ -129,7 +169,7 @@ def main():
|
||||||
valid={},
|
valid={},
|
||||||
)
|
)
|
||||||
|
|
||||||
for dep in (module.params.get('dependencies') or []):
|
for dep in module.params['dependencies']:
|
||||||
match = pkg_dep_re.match(dep)
|
match = pkg_dep_re.match(dep)
|
||||||
if not match:
|
if not match:
|
||||||
module.fail_json(msg="Failed to parse version requirement '{0}'. Must be formatted like 'ansible>2.6'".format(dep))
|
module.fail_json(msg="Failed to parse version requirement '{0}'. Must be formatted like 'ansible>2.6'".format(dep))
|
||||||
|
@ -161,6 +201,7 @@ def main():
|
||||||
module.exit_json(
|
module.exit_json(
|
||||||
python=sys.executable,
|
python=sys.executable,
|
||||||
python_version=sys.version,
|
python_version=sys.version,
|
||||||
|
python_version_info=python_version_info,
|
||||||
python_system_path=sys.path,
|
python_system_path=sys.path,
|
||||||
**results
|
**results
|
||||||
)
|
)
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
that:
|
that:
|
||||||
- "'python' in basic_info"
|
- "'python' in basic_info"
|
||||||
- "'python_version' in basic_info"
|
- "'python_version' in basic_info"
|
||||||
|
- basic_info.python_version_info == ansible_python.version
|
||||||
|
|
||||||
- name: run python_requirements_info module
|
- name: run python_requirements_info module
|
||||||
python_requirements_info:
|
python_requirements_info:
|
||||||
|
|
Loading…
Reference in a new issue