summaryrefslogtreecommitdiff
path: root/clustering/consul.py
diff options
context:
space:
mode:
authorSun JianKang <sjkyspa@gmail.com>2016-04-25 15:58:07 +0800
committerRené Moser <mail@renemoser.net>2016-04-25 09:58:07 +0200
commit08f5a3b6d0e0bbabae278418d02974d446ee4c50 (patch)
tree0b46060352cfcb3060b52ff90e1938887dc6a78a /clustering/consul.py
parentd3a34c0b2c91c9661ec63514c1589e7bd0e60fba (diff)
downloadansible-modules-extras-08f5a3b6d0e0bbabae278418d02974d446ee4c50.tar.gz
add service address when register service (#1299)
Diffstat (limited to 'clustering/consul.py')
-rw-r--r--clustering/consul.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/clustering/consul.py b/clustering/consul.py
index f0df2368..4d05ebc4 100644
--- a/clustering/consul.py
+++ b/clustering/consul.py
@@ -93,6 +93,11 @@ options:
- the port on which the service is listening required for
registration of a service, i.e. if service_name or service_id is set
required: false
+ service_address:
+ description:
+ - the address on which the service is serving required for
+ registration of a service
+ required: false
tags:
description:
- a list of tags that will be attached to the service registration.
@@ -178,6 +183,12 @@ EXAMPLES = '''
interval: 60s
http: /status
+ - name: register nginx with address
+ consul:
+ service_name: nginx
+ service_port: 80
+ service_address: 127.0.0.1
+
- name: register nginx with some service tags
consul:
service_name: nginx
@@ -360,6 +371,7 @@ def parse_service(module):
return ConsulService(
module.params.get('service_id'),
module.params.get('service_name'),
+ module.params.get('service_address'),
module.params.get('service_port'),
module.params.get('tags'),
)
@@ -368,13 +380,14 @@ def parse_service(module):
module.fail_json( msg="service_name supplied but no service_port, a port is required to configure a service. Did you configure the 'port' argument meaning 'service_port'?")
-class ConsulService():
+class ConsulService():
- def __init__(self, service_id=None, name=None, port=-1,
+ def __init__(self, service_id=None, name=None, address=None, port=-1,
tags=None, loaded=None):
self.id = self.name = name
if service_id:
self.id = service_id
+ self.address = address
self.port = port
self.tags = tags
self.checks = []
@@ -391,6 +404,7 @@ class ConsulService():
consul_api.agent.service.register(
self.name,
service_id=self.id,
+ address=self.address,
port=self.port,
tags=self.tags,
check=check.check)
@@ -398,6 +412,7 @@ class ConsulService():
consul_api.agent.service.register(
self.name,
service_id=self.id,
+ address=self.address,
port=self.port,
tags=self.tags)
@@ -527,6 +542,7 @@ def main():
script=dict(required=False),
service_id=dict(required=False),
service_name=dict(required=False),
+ service_address=dict(required=False, type='str', default='localhost'),
service_port=dict(required=False, type='int'),
state=dict(default='present', choices=['present', 'absent']),
interval=dict(required=False, type='str'),