add service address when register service (#1299)

reviewable/pr18780/r1
Sun JianKang 9 years ago committed by René Moser
parent d3a34c0b2c
commit 08f5a3b6d0

@ -93,6 +93,11 @@ options:
- the port on which the service is listening required for - the port on which the service is listening required for
registration of a service, i.e. if service_name or service_id is set registration of a service, i.e. if service_name or service_id is set
required: false required: false
service_address:
description:
- the address on which the service is serving required for
registration of a service
required: false
tags: tags:
description: description:
- a list of tags that will be attached to the service registration. - a list of tags that will be attached to the service registration.
@ -178,6 +183,12 @@ EXAMPLES = '''
interval: 60s interval: 60s
http: /status 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 - name: register nginx with some service tags
consul: consul:
service_name: nginx service_name: nginx
@ -360,6 +371,7 @@ def parse_service(module):
return ConsulService( return ConsulService(
module.params.get('service_id'), module.params.get('service_id'),
module.params.get('service_name'), module.params.get('service_name'),
module.params.get('service_address'),
module.params.get('service_port'), module.params.get('service_port'),
module.params.get('tags'), module.params.get('tags'),
) )
@ -370,11 +382,12 @@ def parse_service(module):
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): tags=None, loaded=None):
self.id = self.name = name self.id = self.name = name
if service_id: if service_id:
self.id = service_id self.id = service_id
self.address = address
self.port = port self.port = port
self.tags = tags self.tags = tags
self.checks = [] self.checks = []
@ -391,6 +404,7 @@ class ConsulService():
consul_api.agent.service.register( consul_api.agent.service.register(
self.name, self.name,
service_id=self.id, service_id=self.id,
address=self.address,
port=self.port, port=self.port,
tags=self.tags, tags=self.tags,
check=check.check) check=check.check)
@ -398,6 +412,7 @@ class ConsulService():
consul_api.agent.service.register( consul_api.agent.service.register(
self.name, self.name,
service_id=self.id, service_id=self.id,
address=self.address,
port=self.port, port=self.port,
tags=self.tags) tags=self.tags)
@ -527,6 +542,7 @@ def main():
script=dict(required=False), script=dict(required=False),
service_id=dict(required=False), service_id=dict(required=False),
service_name=dict(required=False), service_name=dict(required=False),
service_address=dict(required=False, type='str', default='localhost'),
service_port=dict(required=False, type='int'), service_port=dict(required=False, type='int'),
state=dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),
interval=dict(required=False, type='str'), interval=dict(required=False, type='str'),

Loading…
Cancel
Save