consul
Add, modify & delete services within a Consul cluster
Collection: community.general
Full Name: community.general.consul
Synopsis
Add, modify & delete services within a Consul cluster
Parameters
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| check_host | string | Host name. | ||
| check_id | string | An ID for the service check. If O(state=absent), defaults to O(check_name). Ignored if part of a service definition. | ||
| check_name | string | Name for the service check. Required if standalone, ignored if part of service definition. | ||
| check_node | string | Node name. | ||
| host | string | localhost | Host of the Consul agent defaults to localhost. | |
| http | string | Checks can be registered with an HTTP endpoint. This means that Consul checks that the http endpoint returns a successful HTTP status. Requires O(interval) to be provided. Mutually exclusive with O(script), O(ttl) and O(tcp). | ||
| interval | string | The interval at which the service check is run. This is a number with a V(s) or V(m) suffix to signify the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) is used by default, for example V(10) is V(10s). Required if one of the parameters O(script), O(http), or O(tcp) is specified. | ||
| notes | string | Notes to attach to check when registering it. | ||
| port | int | 8500 | The port on which the Consul agent is running. | |
| scheme | string | http | The protocol scheme on which the Consul agent is running. | |
| script | string | The script/command that is run periodically to check the health of the service. Requires O(interval) to be provided. Mutually exclusive with O(ttl), O(tcp) and O(http). | ||
| service_address | string | The address to advertise that the service is listening on. This value is passed as the C(address) parameter to Consul’s C(/v1/agent/service/register) API method, so refer to the Consul API documentation for further details. | ||
| service_id | string | The ID for the service, must be unique per node. If O(state=absent), defaults to the service name if supplied. | ||
| service_name | string | Unique name for the service on a node, must be unique per node, required if registering a service. May be omitted if registering a node level check. | ||
| service_port | int | The port on which the service is listening. Can optionally be supplied for registration of a service, that is if O(service_name) or O(service_id) is set. | ||
| state | string | present | Register or deregister the Consul service, defaults to present. | |
| tags | list | Tags that are attached to the service registration. | ||
| tcp | string | Checks can be registered with a TCP port. This means that Consul checks if the connection attempt to that port is successful (that is, the port is currently accepting connections). The format is V(host:port), for example V(localhost:80). Requires O(interval) to be provided. Mutually exclusive with O(script), O(ttl) and O(http). | ||
| timeout | string | A custom HTTP check timeout. The Consul default is 10 seconds. Similar to the interval this is a number with a V(s) or V(m) suffix to signify the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) is used by default, for example V(10) is equivalent to V(10s). | ||
| token | string | The token key identifying an ACL rule set. May be required to register services. | ||
| ttl | string | Checks can be registered with a TTL instead of a O(script) and O(interval) this means that the service checks in with the agent before the TTL expires. If it does not the check is considered failed. Required if registering a check and the script an interval are missing Similar to the interval this is a number with a V(s) or V(m) suffix to signify the units of seconds or minutes, for example V(15s) or V(1m). If no suffix is supplied V(s) is used by default, for example V(10) is equivalent to V(10s). Mutually exclusive with O(script), O(tcp) and O(http). | ||
| validate_certs | bool | true | Whether to verify the TLS certificate of the Consul agent. |
Example
yaml
- community.general.consul:
service_name: nginx
service_port: 80
name: Register nginx service with the local Consul agent
- community.general.consul:
interval: 60s
script: curl http://localhost
service_name: nginx
service_port: 80
name: Register nginx service with curl check
- community.general.consul:
interval: 60s
service_name: nginx
service_port: 80
tcp: localhost:80
name: register nginx with a tcp check
- community.general.consul:
http: http://localhost:80/status
interval: 60s
service_name: nginx
service_port: 80
name: Register nginx with an http check
- community.general.consul:
service_address: 10.1.5.23
service_name: nginx
service_port: 80
name: Register external service nginx available at 10.1.5.23
- community.general.consul:
service_name: nginx
service_port: 80
tags:
- prod
- webservers
name: Register nginx with some service tags
- community.general.consul:
service_name: nginx
state: absent
name: Remove nginx service
- community.general.consul:
service_name: celery-worker
tags:
- prod
- worker
name: Register celery worker service