updated parameter name and added versioning to python-dateutil
parent
160b24146f
commit
b711ee4f67
|
@ -18,7 +18,7 @@ description:
|
||||||
- "This module allows one to generate or delete GPG private and public keys using GnuPG (gpg)."
|
- "This module allows one to generate or delete GPG private and public keys using GnuPG (gpg)."
|
||||||
requirements:
|
requirements:
|
||||||
- gpg >= 2.1
|
- gpg >= 2.1
|
||||||
- python-dateutil
|
- python-dateutil >= 2.7.0
|
||||||
extends_documentation_fragment:
|
extends_documentation_fragment:
|
||||||
- community.crypto.attributes
|
- community.crypto.attributes
|
||||||
attributes:
|
attributes:
|
||||||
|
@ -120,8 +120,8 @@ options:
|
||||||
- Also excepts dates in ISO formats.
|
- Also excepts dates in ISO formats.
|
||||||
- If left unspecified, any created GPG keys never expire.
|
- If left unspecified, any created GPG keys never expire.
|
||||||
- This module will fail if an unsupported format for O(expire_date) is provided.
|
- This module will fail if an unsupported format for O(expire_date) is provided.
|
||||||
- This module will fail if O(expire_date) is provided, the python-dateutil package is not found, and O(install_python_dateutil=false).
|
- This module will fail if O(expire_date) is provided, the python-dateutil package is not found, and O(install_dateutil=false).
|
||||||
- This module will fail if O(expire_date) is provided, the python-dateutil package is not found, O(install_python_dateutil=true), and check_mode is enabled.
|
- This module will fail if O(expire_date) is provided, the python-dateutil package is not found, O(install_dateutil=true), and check_mode is true.
|
||||||
type: str
|
type: str
|
||||||
name:
|
name:
|
||||||
description:
|
description:
|
||||||
|
@ -152,7 +152,7 @@ options:
|
||||||
- This parameter is ignored if O(state=absent).
|
- This parameter is ignored if O(state=absent).
|
||||||
type: bool
|
type: bool
|
||||||
default: true
|
default: true
|
||||||
install_python_dateutil:
|
install_dateutil:
|
||||||
description:
|
description:
|
||||||
- Specifies whether or not to try to install python-dateutil package if not found.
|
- Specifies whether or not to try to install python-dateutil package if not found.
|
||||||
type: str
|
type: str
|
||||||
|
@ -225,6 +225,7 @@ from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.common.process import get_bin_path
|
from ansible.module_utils.common.process import get_bin_path
|
||||||
from ansible.module_utils.common.respawn import has_respawned, respawn_module
|
from ansible.module_utils.common.respawn import has_respawned, respawn_module
|
||||||
|
|
||||||
|
|
||||||
def all_permutations(arr):
|
def all_permutations(arr):
|
||||||
return list(chain.from_iterable(
|
return list(chain.from_iterable(
|
||||||
permutations(arr, i + 1)
|
permutations(arr, i + 1)
|
||||||
|
@ -380,22 +381,22 @@ def run_module(module, params, check_mode=False):
|
||||||
import dateutil.parser as dp
|
import dateutil.parser as dp
|
||||||
dp.isoparse(params['expire_date'])
|
dp.isoparse(params['expire_date'])
|
||||||
except ImportError:
|
except ImportError:
|
||||||
if params['install_python_dateutil']:
|
if params['install_dateutil']:
|
||||||
apt_pkg_name = 'python-dateutil'
|
pip_package = 'python-dateutil>=2.7.0'
|
||||||
if has_respawned():
|
if has_respawned():
|
||||||
module.fail_json(msg="{0} must be installed and visible from {1}.".format(apt_pkg_name, sys.executable))
|
module.fail_json(msg="{0} must be installed and visible from {1}.".format(pip_package, sys.executable))
|
||||||
elif module.check_mode:
|
elif module.check_mode:
|
||||||
module.fail_json("{} must be installed to use check mode. If run normally this module can auto-install it.".format(apt_pkg_name))
|
module.fail_json("{} must be installed to use check mode. If run normally this module can auto-install it.".format(pip_package))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
module.run_command(
|
module.run_command(
|
||||||
['-m', 'pip', 'install', apt_pkg_name],
|
['-m', 'pip', 'install', pip_package],
|
||||||
executable=sys.executable
|
executable=sys.executable,
|
||||||
check_rc=True
|
check_rc=True
|
||||||
)
|
)
|
||||||
respawn_module(sys.executable) # process will exit here once respawned module has completed
|
respawn_module(sys.executable) # process will exit here once respawned module has completed
|
||||||
else:
|
else:
|
||||||
module.fail_json('An expire date was specified, but the python-dateutil package was not found and install_python_dateutil=false.')
|
module.fail_json('An expire date was specified, but the python-dateutil package was not found and install_dateutil=false.')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
if not (params['expire_date'].isnumeric() or (params['expire_date'][:-1].isnumeric() and params['expire_date'][-1] in ['w', 'm', 'y'])):
|
if not (params['expire_date'].isnumeric() or (params['expire_date'][:-1].isnumeric() and params['expire_date'][-1] in ['w', 'm', 'y'])):
|
||||||
module.fail_json('Invalid format for expire date.')
|
module.fail_json('Invalid format for expire date.')
|
||||||
|
@ -520,7 +521,7 @@ def main():
|
||||||
passphrase=dict(type='str', no_log=True),
|
passphrase=dict(type='str', no_log=True),
|
||||||
fingerprints=dict(type='list', elements='str', default=[]),
|
fingerprints=dict(type='list', elements='str', default=[]),
|
||||||
force=dict(type='bool', default=False),
|
force=dict(type='bool', default=False),
|
||||||
install_python_dateutil=dict(type='bool', default=True)
|
install_dateutil=dict(type='bool', default=True)
|
||||||
),
|
),
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
required_if=[
|
required_if=[
|
||||||
|
|
Loading…
Reference in New Issue