1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[PR #5772/cc79c24c backport][stable-6] consul: deprecate params incompatible with state=absent (#5831)

consul: deprecate params incompatible with state=absent (#5772)

* consul: deprecate params incompatible with state=absent

* Refrain from handling SystemExit exception

* preposition

* add changelog fragment

* Update plugins/modules/consul.py

* Update changelogs/fragments/5772-consul-deprecate-params-when-absent.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit cc79c24c01)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2023-01-13 21:23:08 +01:00 committed by GitHub
parent 1da5f7dc54
commit 474364c862
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View file

@ -0,0 +1,2 @@
deprecated_features:
- consul - deprecate using parameters unused for ``state=absent`` (https://github.com/ansible-collections/community.general/pull/5772).

View file

@ -149,6 +149,10 @@ options:
type: str
description:
- The token key identifying an ACL rule set. May be required to register services.
ack_params_state_absent:
type: bool
description:
- Disable deprecation warning when using parameters incompatible with I(state=absent).
'''
EXAMPLES = '''
@ -584,7 +588,8 @@ def main():
http=dict(type='str'),
timeout=dict(type='str'),
tags=dict(type='list', elements='str'),
token=dict(no_log=True)
token=dict(no_log=True),
ack_params_state_absent=dict(type='bool'),
),
required_if=[
('state', 'present', ['service_name']),
@ -592,14 +597,29 @@ def main():
],
supports_check_mode=False,
)
p = module.params
test_dependencies(module)
if p['state'] == 'absent' and any(p[x] for x in ['script', 'ttl', 'tcp', 'http', 'interval']) and not p['ack_params_state_absent']:
module.deprecate(
"The use of parameters 'script', 'ttl', 'tcp', 'http', 'interval' along with 'state=absent' is deprecated. "
"In community.general 8.0.0 their use will become an error. "
"To suppress this deprecation notice, set parameter ack_params_state_absent=true.",
version="8.0.0",
collection_name="community.general",
)
# When reaching c.g 8.0.0:
# - Replace the deprecation with a fail_json(), remove the "ack_params_state_absent" condition from the "if"
# - Add mutually_exclusive for ('script', 'ttl', 'tcp', 'http'), then remove that validation from parse_check()
# - Add required_by {'script': 'interval', 'http': 'interval', 'tcp': 'interval'}, then remove checks for 'interval' in ConsulCheck.__init__()
# - Deprecate the parameter ack_params_state_absent
try:
register_with_consul(module)
except SystemExit:
raise
except ConnectionError as e:
module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (
module.params['host'], module.params['port'], str(e)))
module.fail_json(msg='Could not connect to consul agent at %s:%s, error was %s' % (p['host'], p['port'], str(e)))
except Exception as e:
module.fail_json(msg=str(e))