community.general.consul module – Add, modify & delete services within a consul cluster
Note
This module is part of the community.general collection (version 9.5.1).
You might already have this collection installed if you are using the ansible
package.
It is not included in ansible-core
.
To check whether it is installed, run ansible-galaxy collection list
.
To install it, use: ansible-galaxy collection install community.general
.
You need further requirements to be able to use this module,
see Requirements for details.
To use it in a playbook, specify: community.general.consul
.
Synopsis
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 acheck_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.
Requirements
The below requirements are needed on the host that executes this module.
python-consul
requests
Parameters
Parameter |
Comments |
---|---|
This parameter has no more effect and is deprecated. It will be removed in community.general 10.0.0. Choices:
|
|
Host name. |
|
An ID for the service check. If |
|
Name for the service check. Required if standalone, ignored if part of service definition. |
|
Node name. |
|
Host of the consul agent defaults to localhost. Default: |
|
The interval at which the service check will be run. This is a number with a Required if one of the parameters |
|
Notes to attach to check when registering it. |
|
The port on which the consul agent is running. Default: |
|
The protocol scheme on which the consul agent is running. Default: |
|
The address to advertise that the service will be listening on. This value will be passed as the |
|
The ID for the service, must be unique per node. If |
|
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. |
|
The port on which the service is listening. Can optionally be supplied for registration of a service, that is if |
|
Register or deregister the consul service, defaults to present. Choices:
|
|
Tags that will be attached to the service registration. |
|
Checks can be registered with a TCP port. This means that consul will check if the connection attempt to that port is successful (that is, the port is currently accepting connections). The format is Requires |
|
A custom HTTP check timeout. The consul default is 10 seconds. Similar to the interval this is a number with a |
|
The token key identifying an ACL rule set. May be required to register services. |
|
Checks can be registered with a TTL instead of a |
|
Whether to verify the TLS certificate of the consul agent. Choices:
|
Attributes
Attribute |
Support |
Description |
---|---|---|
Support: none |
Can run in |
|
Support: none |
Will return details on what has changed (or possibly needs changing in |
Examples
- name: Register nginx service with the local consul agent
community.general.consul:
service_name: nginx
service_port: 80
- name: Register nginx service with curl check
community.general.consul:
service_name: nginx
service_port: 80
script: curl http://localhost
interval: 60s
- name: register nginx with a tcp check
community.general.consul:
service_name: nginx
service_port: 80
interval: 60s
tcp: localhost:80
- name: Register nginx with an http check
community.general.consul:
service_name: nginx
service_port: 80
interval: 60s
http: http://localhost:80/status
- name: Register external service nginx available at 10.1.5.23
community.general.consul:
service_name: nginx
service_port: 80
service_address: 10.1.5.23
- name: Register nginx with some service tags
community.general.consul:
service_name: nginx
service_port: 80
tags:
- prod
- webservers
- name: Remove nginx service
community.general.consul:
service_name: nginx
state: absent
- name: Register celery worker service
community.general.consul:
service_name: celery-worker
tags:
- prod
- worker
- name: Create a node level check to test disk usage
community.general.consul:
check_name: Disk usage
check_id: disk_usage
script: /opt/disk_usage.py
interval: 5m
- name: Register an http check against a service that's already registered
community.general.consul:
check_name: nginx-check2
check_id: nginx-check2
service_id: nginx
interval: 60s
http: http://localhost:80/morestatus