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 consul's discovery mechanism. It may optionally supply a check definition, 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 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 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, there is no complete way to retrieve the script, interval or ttl metadata for a registered check. Without this metadata it is not possible to tell if the data supplied with ansible represents a change to a check. As a result this does not attempt to determine changes and will always report a changed occurred. An api method is planned to supply this metadata so at that stage change management will be added. ,See http://consul.io for more details.

Options

namedescriptionrequiredchoices
state register or deregister the consul service, defaults to present true
  • present
  • absent
service_name 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
service_id the ID for the service, must be unique per node, defaults to the service name if the service name is supplied
host host of the consul agent defaults to localhost
port the port on which the consul agent is running
notes Notes to attach to check when registering it.
service_port the port on which the service is listening required for registration of a service, i.e. if service_name or service_id is set
tags 1. list of tags that will be attached to the service registration.
script the script/command that will be run periodically to check the health of the service. Scripts require an interval and vise versa
interval the interval at which the service check will be run. 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 if the script param is specified.
check_id an ID for the service check, defaults to the check name, ignored if part of a service definition.
check_name 1. name for the service check, defaults to the check id. required if standalone, ignored if part of service definition.
ttl 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
http checks can be registered with an http endpoint. This means that consul will check that the http endpoint returns a successful http status. Interval must also be provided with this option.
timeout 1. custom HTTP check timeout. The consul default is 10 seconds. 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.
token the token key indentifying an ACL rule set. May be required to register services.

Author

Steve Gargan (@sgargan)