summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Aleman <alvaroaleman@users.noreply.github.com>2018-03-06 17:57:04 +0100
committerToshio Kuratomi <a.badger@gmail.com>2018-03-29 14:12:42 -0700
commit5d604d7ecd707bc1e72cce56727c76d4fbe64809 (patch)
tree02540c8436956ab304fb0cd025ddd81aef796cef
parentb9c94cc0c4f43944867ae4a1c664081217c786a2 (diff)
downloadansible-5d604d7ecd707bc1e72cce56727c76d4fbe64809.tar.gz
Fix consul module service deregistration (#34847)
* Fix consul module service deregistration Upstream pr in the python-consul library: https://github.com/cablehead/python-consul/pull/174 This is based on work from https://github.com/bobh Fixes ansible/ansible#34628 * Pass ACL token when deregistering consul service (cherry picked from commit c9cb0016a02b96c3582761aabae0c959c32c89cb)
-rw-r--r--lib/ansible/modules/clustering/consul.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/ansible/modules/clustering/consul.py b/lib/ansible/modules/clustering/consul.py
index 72dc892ea2..c44a19e023 100644
--- a/lib/ansible/modules/clustering/consul.py
+++ b/lib/ansible/modules/clustering/consul.py
@@ -228,6 +228,16 @@ EXAMPLES = '''
try:
import consul
from requests.exceptions import ConnectionError
+
+ class PatchedConsulAgentService(consul.Consul.Agent.Service):
+ def deregister(self, service_id, token=None):
+ params = {}
+ if token:
+ params['token'] = token
+ return self.agent.http.put(consul.base.CB.bool(),
+ '/v1/agent/service/deregister/%s' % service_id,
+ params=params)
+
python_consul_installed = True
except ImportError:
python_consul_installed = False
@@ -337,18 +347,20 @@ def remove_service(module, service_id):
consul_api = get_consul_api(module)
service = get_service_by_id_or_name(consul_api, service_id)
if service:
- consul_api.agent.service.deregister(service_id)
+ consul_api.agent.service.deregister(service_id, token=module.params.get('token'))
module.exit_json(changed=True, id=service_id)
module.exit_json(changed=False, id=service_id)
def get_consul_api(module, token=None):
- return consul.Consul(host=module.params.get('host'),
- port=module.params.get('port'),
- scheme=module.params.get('scheme'),
- verify=module.params.get('validate_certs'),
- token=module.params.get('token'))
+ consulClient = consul.Consul(host=module.params.get('host'),
+ port=module.params.get('port'),
+ scheme=module.params.get('scheme'),
+ verify=module.params.get('validate_certs'),
+ token=module.params.get('token'))
+ consulClient.agent.service = PatchedConsulAgentService(consulClient)
+ return consulClient
def get_service_by_id_or_name(consul_api, service_id_or_name):