community.general.consul_agent_service module – Add, modify and 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
.
To use it in a playbook, specify: community.general.consul_agent_service
.
New in community.general 9.1.0
Synopsis
Allows the addition, modification and deletion of services in a consul cluster via the agent.
There are currently no plans to create services and checks in one. This is because the Consul API does not provide checks for a service and the checks themselves do not match the module parameters. Therefore, only a service without checks can be created in this module.
Parameters
Parameter |
Comments |
---|---|
The address to advertise that the service will be listening on. This value will be passed as the |
|
The CA bundle to use for https connections |
|
Specifies to disable the anti-entropy feature for this service’s tags. If EnableTagOverride is set to true then external agents can update this service in the catalog and modify the tags. Choices:
|
|
Host of the consul agent, defaults to Default: |
|
Specifies a unique ID for this service. This must be unique per agent. This defaults to the |
|
Optional meta data used for filtering. For keys, the characters |
|
Unique name for the service on a node, must be unique per node, required if registering a service. |
|
The port on which the consul agent is running. Default: |
|
The protocol scheme on which the consul agent is running. Defaults to Default: |
|
Whether the service should be present or absent. Choices:
|
|
Tags that will be attached to the service registration. |
|
The token to use for authorization. |
|
Whether to verify the TLS certificate of the consul agent. Choices:
|
|
Specifies weights for the service Default: |
|
Weights for passing. Default: |
|
Weights for warning. Default: |
Attributes
Attribute |
Support |
Description |
---|---|---|
Action group: community.general.consul |
Use |
|
Support: full |
Can run in |
|
Support: partial In check mode the diff will miss operational attributes. |
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_agent_service:
host: consul1.example.com
token: some_management_acl
name: nginx
service_port: 80
- name: Register nginx with a tcp check
community.general.consul_agent_service:
host: consul1.example.com
token: some_management_acl
name: nginx
service_port: 80
- name: Register nginx with an http check
community.general.consul_agent_service:
host: consul1.example.com
token: some_management_acl
name: nginx
service_port: 80
- name: Register external service nginx available at 10.1.5.23
community.general.consul_agent_service:
host: consul1.example.com
token: some_management_acl
name: nginx
service_port: 80
address: 10.1.5.23
- name: Register nginx with some service tags
community.general.consul_agent_service:
host: consul1.example.com
token: some_management_acl
name: nginx
service_port: 80
tags:
- prod
- webservers
- name: Register nginx with some service meta
community.general.consul_agent_service:
host: consul1.example.com
token: some_management_acl
name: nginx
service_port: 80
meta:
nginx_version: 1.25.3
- name: Remove nginx service
community.general.consul_agent_service:
host: consul1.example.com
token: some_management_acl
service_id: nginx
state: absent
- name: Register celery worker service
community.general.consul_agent_service:
host: consul1.example.com
token: some_management_acl
name: celery-worker
tags:
- prod
- worker
Return Values
Common return values are documented here, the following are the fields unique to this module:
Key |
Description |
---|---|
The operation performed. Returned: changed Sample: |
|
The service as returned by the consul HTTP API. Returned: always Sample: |