diff --git a/lib/ansible/modules/clustering/consul.py b/lib/ansible/modules/clustering/consul.py index 29212635cfb..aeb87874465 100644 --- a/lib/ansible/modules/clustering/consul.py +++ b/lib/ansible/modules/clustering/consul.py @@ -389,8 +389,8 @@ def parse_service(module): module.params.get('service_port'), module.params.get('tags'), ) - elif module.params.get('service_port') and not module.params.get('service_name'): - module.fail_json(msg="service_port supplied but no service_name, a name is required to configure a service.") + elif not module.params.get('service_name'): + module.fail_json(msg="service_name is required to configure a service.") class ConsulService(): diff --git a/test/integration/roles/test_consul_service/tasks/main.yml b/test/integration/roles/test_consul_service/tasks/main.yml index ce9ac29cfbb..2fd593b1b35 100644 --- a/test/integration/roles/test_consul_service/tasks/main.yml +++ b/test/integration/roles/test_consul_service/tasks/main.yml @@ -47,6 +47,17 @@ - basic2_result.service_id == 'service2' - basic2_result.service_name == 'Basic Service' +- name: register service without name + consul: + service_id: this_will_fail + register: noname_result + ignore_errors: True + +- name: verify registering service without name fails + assert: + that: + - noname_result | failed + - name: register very basic service without service_port consul: service_name: Basic Service Without Port