|
|
@ -24,19 +24,19 @@ short_description: "Add, modify & delete services within a consul cluster.
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- registers services and checks for an agent with a consul cluster. A service
|
|
|
|
- registers services and checks for an agent with a consul cluster. A service
|
|
|
|
is some process running on the agent node that should be advertised by
|
|
|
|
is some process running on the agent node that should be advertised by
|
|
|
|
consul's discovery mechanism. It may optionally supply a check definition
|
|
|
|
consul's discovery mechanism. It may optionally supply a check definition,
|
|
|
|
that will be used to notify the consul cluster of the health of the service.
|
|
|
|
a periodic service test to notify the consul cluster of service's health.
|
|
|
|
Checks may also be registered per node e.g. disk usage, or cpu usage and
|
|
|
|
Checks may also be registered per node e.g. disk usage, or cpu usage and
|
|
|
|
notify the health of the entire node to the cluster.
|
|
|
|
notify the health of the entire node to the cluster.
|
|
|
|
Service level checks do not require a check name or id as these are derived
|
|
|
|
Service level checks do not require a check name or id as these are derived
|
|
|
|
by Consul from the Service name and id respectively by appending 'service:'.
|
|
|
|
by Consul from the Service name and id respectively by appending 'service:'.
|
|
|
|
Node level checks require a check_name and optionally a check_id Currently,
|
|
|
|
Node level checks require a check_name and optionally a check_id.
|
|
|
|
there is no complete way to retrieve the script, interval or ttl metadata for
|
|
|
|
Currently, there is no complete way to retrieve the script, interval or ttl
|
|
|
|
a registered check. Without this metadata it is not possible to tell if
|
|
|
|
metadata for a registered check. Without this metadata it is not possible to
|
|
|
|
the data supplied with ansible represents a change to a check. As a result
|
|
|
|
tell if the data supplied with ansible represents a change to a check. As a
|
|
|
|
this does not attempt to determine changes and will always report a changed
|
|
|
|
result this does not attempt to determine changes and will always report a
|
|
|
|
occurred. An api method is planned to supply this metadata so at that stage
|
|
|
|
changed occurred. An api method is planned to supply this metadata so at that
|
|
|
|
change management will be added.
|
|
|
|
stage change management will be added.
|
|
|
|
version_added: "1.9"
|
|
|
|
version_added: "1.9"
|
|
|
|
author: Steve Gargan (steve.gargan@gmail.com)
|
|
|
|
author: Steve Gargan (steve.gargan@gmail.com)
|
|
|
|
options:
|
|
|
|
options:
|
|
|
@ -45,71 +45,105 @@ options:
|
|
|
|
- register or deregister the consul service, defaults to present
|
|
|
|
- register or deregister the consul service, defaults to present
|
|
|
|
required: true
|
|
|
|
required: true
|
|
|
|
choices: ['present', 'absent']
|
|
|
|
choices: ['present', 'absent']
|
|
|
|
|
|
|
|
service_name:
|
|
|
|
|
|
|
|
desciption:
|
|
|
|
|
|
|
|
- Unique name for the service on a node, must be unique per node,
|
|
|
|
|
|
|
|
required if registering a service. May be ommitted if registering
|
|
|
|
|
|
|
|
a node level check
|
|
|
|
|
|
|
|
required: false
|
|
|
|
service_id:
|
|
|
|
service_id:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- the ID for the service, must be unique per node, defaults to the
|
|
|
|
- the ID for the service, must be unique per node, defaults to the
|
|
|
|
service name
|
|
|
|
service name if the service name is supplied
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: service_name if supplied
|
|
|
|
host:
|
|
|
|
host:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- host of the consul agent with which to register the service,
|
|
|
|
- host of the consul agent defaults to localhost
|
|
|
|
defaults to localhost
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: localhost
|
|
|
|
|
|
|
|
port:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- the port on which the consul agent is running
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: 8500
|
|
|
|
notes:
|
|
|
|
notes:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Notes to attach to check when registering it.
|
|
|
|
- Notes to attach to check when registering it.
|
|
|
|
service_name:
|
|
|
|
|
|
|
|
desciption:
|
|
|
|
|
|
|
|
- Unique name for the service on a node, must be unique per node,
|
|
|
|
|
|
|
|
required if registering a service. May be ommitted if registering
|
|
|
|
|
|
|
|
a node level check
|
|
|
|
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
service_port:
|
|
|
|
service_port:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- the port on which the service is listening required for
|
|
|
|
- the port on which the service is listening required for
|
|
|
|
registration of a service.
|
|
|
|
registration of a service, i.e. if service_name or service_id is set
|
|
|
|
required: true
|
|
|
|
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.
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
script:
|
|
|
|
script:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- the script/command that will be run periodically to check the health
|
|
|
|
- the script/command that will be run periodically to check the health
|
|
|
|
of the service
|
|
|
|
of the service. Scripts require an interval and vise versa
|
|
|
|
required: false
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
interval:
|
|
|
|
interval:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- the interval at which the service check will be run. This is by
|
|
|
|
- the interval at which the service check will be run. This is a number
|
|
|
|
convention a number with a s or m to signify the units of seconds
|
|
|
|
with a s or m suffix to signify the units of seconds or minutes e.g
|
|
|
|
or minutes. if none is supplied, m will be appended
|
|
|
|
15s or 1m. If no suffix is supplied, m will be used by default e.g.
|
|
|
|
|
|
|
|
1 will be 1m. Required if the script param is specified.
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
check_id:
|
|
|
|
check_id:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- an ID for the service check, defaults to the check name, ignored if
|
|
|
|
- an ID for the service check, defaults to the check name, ignored if
|
|
|
|
part of service definition.
|
|
|
|
part of a service definition.
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
check_name:
|
|
|
|
check_name:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- a name for the service check, defaults to the check id. required if
|
|
|
|
- a name for the service check, defaults to the check id. required if
|
|
|
|
standalone, ignored if part of service definition.
|
|
|
|
standalone, ignored if part of service definition.
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
|
|
|
|
ttl:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- checks can be registered with a ttl instead of a script and interval
|
|
|
|
|
|
|
|
this means that the service will check in with the agent before the
|
|
|
|
|
|
|
|
ttl expires. If it doesn't the check will be considered failed.
|
|
|
|
|
|
|
|
Required if registering a check and the script an interval are missing
|
|
|
|
|
|
|
|
Similar to the interval this is a number with a s or m suffix to
|
|
|
|
|
|
|
|
signify the units of seconds or minutes e.g 15s or 1m. If no suffix
|
|
|
|
|
|
|
|
is supplied, m will be used by default e.g. 1 will be 1m
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
|
|
|
|
token:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- the token key indentifying an ACL rule set. May be required to
|
|
|
|
|
|
|
|
register services.
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
default: None
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
|
|
|
EXAMPLES = '''
|
|
|
|
- name: register nginx service with the local consul agent
|
|
|
|
- name: register nginx service with the local consul agent
|
|
|
|
consul:
|
|
|
|
consul:
|
|
|
|
name: nginx
|
|
|
|
name: nginx
|
|
|
|
port: 80
|
|
|
|
service_port: 80
|
|
|
|
|
|
|
|
|
|
|
|
- name: register nginx service with curl check
|
|
|
|
- name: register nginx service with curl check
|
|
|
|
consul:
|
|
|
|
consul:
|
|
|
|
name: nginx
|
|
|
|
name: nginx
|
|
|
|
port: 80
|
|
|
|
service_port: 80
|
|
|
|
script: "curl http://localhost"
|
|
|
|
script: "curl http://localhost"
|
|
|
|
interval: 60s
|
|
|
|
interval: 60s
|
|
|
|
|
|
|
|
|
|
|
|
- name: register nginx with some service tags
|
|
|
|
- name: register nginx with some service tags
|
|
|
|
consul:
|
|
|
|
consul:
|
|
|
|
name: nginx
|
|
|
|
name: nginx
|
|
|
|
port: 80
|
|
|
|
service_port: 80
|
|
|
|
tags:
|
|
|
|
tags:
|
|
|
|
- prod
|
|
|
|
- prod
|
|
|
|
- webservers
|
|
|
|
- webservers
|
|
|
@ -432,23 +466,22 @@ class ConsulCheck():
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
argument_spec=dict(
|
|
|
|
|
|
|
|
host=dict(default='localhost'),
|
|
|
|
|
|
|
|
port=dict(default=8500, type='int'),
|
|
|
|
check_id=dict(required=False),
|
|
|
|
check_id=dict(required=False),
|
|
|
|
check_name=dict(required=False),
|
|
|
|
check_name=dict(required=False),
|
|
|
|
host=dict(default='localhost'),
|
|
|
|
|
|
|
|
interval=dict(required=False, type='str'),
|
|
|
|
|
|
|
|
ttl=dict(required=False, type='str'),
|
|
|
|
|
|
|
|
check_node=dict(required=False),
|
|
|
|
check_node=dict(required=False),
|
|
|
|
check_host=dict(required=False),
|
|
|
|
check_host=dict(required=False),
|
|
|
|
notes=dict(required=False),
|
|
|
|
notes=dict(required=False),
|
|
|
|
port=dict(default=8500, type='int'),
|
|
|
|
|
|
|
|
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_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'),
|
|
|
|
|
|
|
|
ttl=dict(required=False, type='str'),
|
|
|
|
tags=dict(required=False, type='list'),
|
|
|
|
tags=dict(required=False, type='list'),
|
|
|
|
token=dict(required=False),
|
|
|
|
token=dict(required=False)
|
|
|
|
url=dict(default='http://localhost:8500')
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
supports_check_mode=False,
|
|
|
|
supports_check_mode=False,
|
|
|
|
)
|
|
|
|
)
|
|
|
|