Skip to content

Commit

Permalink
[PR #5772/cc79c24c backport][stable-6] consul: deprecate params incom…
Browse files Browse the repository at this point in the history
…patible 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 cc79c24)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
  • Loading branch information
patchback[bot] and russoz authored Jan 13, 2023
1 parent 1da5f7d commit 474364c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deprecated_features:
- consul - deprecate using parameters unused for ``state=absent`` (https://github.com/ansible-collections/community.general/pull/5772).
26 changes: 23 additions & 3 deletions plugins/modules/consul.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
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 = '''
Expand Down Expand Up @@ -584,22 +588,38 @@ 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']),
('state', 'absent', ['service_id', 'service_name', 'check_id', 'check_name'], True),
],
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))

Expand Down

0 comments on commit 474364c

Please sign in to comment.