diff --git a/changelogs/fragments/5772-consul-deprecate-params-when-absent.yml b/changelogs/fragments/5772-consul-deprecate-params-when-absent.yml new file mode 100644 index 0000000000..44d681765f --- /dev/null +++ b/changelogs/fragments/5772-consul-deprecate-params-when-absent.yml @@ -0,0 +1,2 @@ +deprecated_features: + - consul - deprecate using parameters unused for ``state=absent`` (https://github.com/ansible-collections/community.general/pull/5772). diff --git a/plugins/modules/consul.py b/plugins/modules/consul.py index ea329254a1..dea853b98e 100644 --- a/plugins/modules/consul.py +++ b/plugins/modules/consul.py @@ -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))