This Ansible role installs Consul, including establishing a filesystem structure and server or client agent configuration with support for some common operational features.
It can also bootstrap a development or evaluation cluster of 3 server agents running in a Vagrant and VirtualBox based environment. See README_VAGRANT.md and the associated Vagrantfile for more details.
“Another flaw in the human character is that everybody wants to build and nobody wants to do maintenance.”
― Kurt Vonnegut, Hocus Pocus
Please note that the original design goal of this role was more concerned with the initial installation and bootstrapping of a Consul server cluster environment and so it does not currently concern itself (all that much) with performing ongoing maintenance of a cluster.
Many users have expressed that the Vagrant based environment makes getting a working local Consul server cluster environment up and running an easy process — so this role will target that experience as a primary motivator for existing.
If you get some mileage from it in other ways, then all the better!
This role was originally developed by Brian Shumate and was known on Ansible Galaxy as brianshumate.consul. Brian asked the community to be relieved of the maintenance burden, and therefore Bas Meijer transferred the role to ansible-community so that a team of volunteers can maintain it. At the moment there is no membership of ansible-community on https://galaxy.ansible.com and therefore to install this role into your project you should create a file requirements.yml
in the subdirectory roles/
of your project with this content:
---
- src: https://github.com/ansible-community/ansible-consul.git
name: ansible-consul
scm: git
version: master
This repo has tagged releases that you can use to pin the version.
Tower will install the role automatically, if you use the CLI to control ansible, then install it like:
ansible-galaxy install -p roles -r roles/requirements.yml
This role requires a FreeBSD, Debian, or Red Hat Enterprise Linux distribution or Windows Server 2012 R2.
The role might work with other OS distributions and versions, but is known to function well with the following software versions:
- Consul: 1.8.7
- Ansible: 2.8.2
- Alma Linux: 8, 9
- Alpine Linux: 3.8
- CentOS: 7, 8
- Debian: 9
- FreeBSD: 11
- Mac OS X: 10.15 (Catalina)
- RHEL: 7, 8
- Rocky Linux: 8
- OracleLinux: 7, 8
- Ubuntu: 16.04
- Windows: Server 2012 R2
Note that for the "local" installation mode (the default), this role will locally download only one instance of the Consul archive, unzip it and install the resulting binary on all desired Consul hosts.
To do so requires that unzip
is available on the Ansible control host and the role will fail if it doesn't detect unzip
in the PATH.
Collection requirements for this role are listed in the requirements.yml
file. It is your responsibility to make sure that you install these collections to ensure that the role runs properly. Usually, this can be done with:
ansible-galaxy collection install -r requirements.yml
This role does not fully support the limit option (ansible -l
) to limit the hosts, as this will break populating required host variables. If you do use the limit option with this role, you can encounter template errors like:
Undefined is not JSON serializable.
The role uses variables defined in these 3 places:
- Hosts inventory file (see
examples/vagrant_hosts
for an example) vars/*.yml
(primarily OS/distributions specific variables)defaults/main.yml
(everything else)
⚠️ NOTE: The role relies on the inventory host group for the consul servers to be defined as the variableconsul_group_name
and it will not function properly otherwise. Alternatively the consul servers can be placed in the default host group[consul_instances]
in the inventory as shown in the examples below.
Many role variables can also take their values from environment variables as well; those are noted in the description where appropriate.
- Version to install
- Set value as
latest
for the latest available version of consul - Default value: 1.8.7
- Dictionary for translating ansible_architecture values to Go architecture values naming convention
- Default value: dict
- System architecture as determined by
{{ consul_architecture_map[ansible_architecture] }}
- Default value (determined at runtime): amd64, arm, or arm64
- Operating system name in lowercase representation
- Default value:
{{ ansible_os_family | lower }}
- Install python and package dependencies required for the role functions.
- Default value: true
- Consul archive file download URL
- Default value:
https://releases.hashicorp.com/consul/{{ consul_version }}/consul_{{ consul_version }}_{{ consul_os }}_{{ consul_architecture }}.zip
- Package SHA256 summaries file URL
- Default value:
https://releases.hashicorp.com/consul/{{ consul_version }}/{{ consul_version }}_SHA256SUMS
- Binary installation path
- Default Linux value:
/usr/local/bin
- Default Windows value:
C:\ProgramData\consul\bin
- Base configuration file path
- Default Linux value:
/etc/consul
- Default Windows value:
C:\ProgramData\consul\config
- Additional configuration directory
- Default Linux value:
{{ consul_config_path }}/consul.d
- Default Windows value:
C:\ProgramData\consul\config.d
- Data directory path as defined in data_dir or -data-dir
- Default Linux value:
/opt/consul
- Default Windows value:
C:\ProgramData\consul\data
- Enable configuration of rsyslogd or syslog-ng on Linux. If disabled, Consul will still log to syslog if
consul_syslog_enable
is true, but the syslog daemon won't be configured to write Consul logs to their own logfile.- Override with
CONSUL_CONFIGURE_SYSLOGD
environment variable
- Override with
- Default Linux value: false
- If
consul_syslog_enable
is false- Log path for use in log_file or -log-file
- If
consul_syslog_enable
is true- Log path for use in rsyslogd configuration on Linux. Ignored if
consul_configure_syslogd
is false.
- Log path for use in rsyslogd configuration on Linux. Ignored if
- Default Linux value:
/var/log/consul
- Override with
CONSUL_LOG_PATH
environment variable
- Override with
- Default Windows value:
C:\ProgramData\consul\log
- If
consul_syslog_enable
is false- Log file for use in log_file or -log-file
- If
consul_syslog_enable
is true- Log file for use in rsyslogd configuration on Linux. Ignored if
consul_configure_syslogd
is false.
- Log file for use in rsyslogd configuration on Linux. Ignored if
- Override with
CONSUL_LOG_FILE
environment variable - Default Linux value:
consul.log
- Log rotate bytes as defined in log_rotate_bytes or -log-rotate-bytes
- Override with
CONSUL_LOG_ROTATE_BYTES
environment variable
- Override with
- Ignored if
consul_syslog_enable
is true - Default value: 0
- Log rotate bytes as defined in log_rotate_duration or -log-rotate-duration
- Override with
CONSUL_LOG_ROTATE_DURATION
environment variable
- Override with
- Ignored if
consul_syslog_enable
is true - Default value: 24h
- Log rotate bytes as defined in log_rotate_max_files or -log-rotate-max-files
- Override with
CONSUL_LOG_ROTATE_MAX_FILES
environment variable
- Override with
- Ignored if
consul_syslog_enable
is true - Default value: 0
- Syslog facility as defined in syslog_facility
- Override with
CONSUL_SYSLOG_FACILITY
environment variable
- Override with
- Default Linux value: local0
- Owner of
rsyslogd
process on Linux.consul_log_path
's ownership is set to this user on Linux. Ignored ifconsul_configure_syslogd
is false.- Override with
SYSLOG_USER
environment variable
- Override with
- Default Linux value: syslog
- Group of user running
rsyslogd
process on Linux.consul_log_path
's group ownership is set to this group on Linux. Ignored ifconsul_configure_syslogd
is false.- Override with
SYSLOG_GROUP
environment variable
- Override with
- Default value: adm
- Run path for process identifier (PID) file
- Default Linux value:
/run/consul
- Default Windows value:
C:\ProgramData\consul
- OS user
- Default Linux value: consul
- Default Windows value: LocalSystem
- Whether to create the user defined by
consul_user
or not - Default value: true
- OS group
- Default value: bin
- Whether to create the group defined by
consul_group
or not - Default value: true
- Inventory group name
- Override with
CONSUL_GROUP_NAME
environment variable
- Override with
- Default value: consul_instances
- Interval for reconnection attempts to LAN servers
- Default value: 30s
- Interval for reconnection attempts to WAN servers
- Default value: 30s
- If true, the config value for retry_join won't be populated by the default hosts servers. The value can be initialized using consul_join
- Default value: false
- Max reconnection attempts to LAN servers before failing (0 = infinite)
- Default value: 0
- Max reconnection attempts to WAN servers before failing (0 = infinite)
- Default value: 0
- List of LAN servers, not managed by this role, to join (IPv4 IPv6 or DNS addresses)
- Default value: []
- List of WAN servers, not managed by this role, to join (IPv4 IPv6 or DNS addresses)
- Default value: []
It's typically not necessary to manually alter this list.
- List of server nodes
- Default value: List of all nodes in
consul_group_name
withconsul_node_role
set to server or bootstrap
- Boolean that adds bootstrap_expect value on Consul servers's config file
- Default value: false
- Integer to define the minimum number of consul servers joined to the cluster in order to elect the leader.
- Default value: Calculated at runtime based on the number of nodes
This feature makes it possible to gather the consul_advertise_address(_wan)
from servers that are currently not targeted by the playbook.
To make this possible the delegate_facts
option is used; note that his option has been problematic.
- Gather facts from servers that are not currently targeted
- Default value: false
- Datacenter label
- Override with
CONSUL_DATACENTER
environment variable- Default value: dc1
- Override with
- Default value: dc1
- Consul domain name as defined in domain or -domain
- Override with
CONSUL_DOMAIN
environment variable
- Override with
- Default value: consul
- Consul domain name as defined in alt_domain or -alt-domain
- Override with
CONSUL_ALT_DOMAIN
environment variable
- Override with
- Default value: Empty string
- Consul node meta data (key-value)
- Supported in Consul version 0.7.3 or later
- Default value: {}
- Example:
consul_node_meta:
node_type: "my-custom-type"
node_meta1: "metadata1"
node_meta2: "metadata2"
- Log level as defined in log_level or -log-level
- Override with
CONSUL_LOG_LEVEL
environment variable
- Override with
- Default value: INFO
- Log to syslog as defined in enable_syslog or -syslog
- Override with
CONSUL_SYSLOG_ENABLE
environment variable
- Override with
- Default Linux value: false
- Default Windows value: false
- Consul network interface
- Override with
CONSUL_IFACE
environment variable
- Override with
- Default value:
{{ ansible_default_ipv4.interface }}
- Bind address
- Override with
CONSUL_BIND_ADDRESS
environment variable
- Override with
- Default value: default ipv4 address, or address of interface configured by
consul_iface
- LAN advertise address
- Default value:
consul_bind_address
- Wan advertise address
- Default value:
consul_bind_address
- Prefer a node's configured WAN address when serving DNS
- Default value: false
- Advanced advertise addresses settings
- Individual addresses can be overwritten using the
consul_advertise_addresses_*
variables - Default value:
consul_advertise_addresses: serf_lan: "{{ consul_advertise_addresses_serf_lan | default(consul_advertise_address+':'+consul_ports.serf_lan) }}" serf_wan: "{{ consul_advertise_addresses_serf_wan | default(consul_advertise_address_wan+':'+consul_ports.serf_wan) }}" rpc: "{{ consul_advertise_addresses_rpc | default(consul_bind_address+':'+consul_ports.server) }}"
- Client address
- Default value: 127.0.0.1
- Advanced address settings
- Individual addresses kan be overwritten using the
consul_addresses_*
variables - Default value:
consul_addresses: dns: "{{ consul_addresses_dns | default(consul_client_address, true) }}" http: "{{ consul_addresses_http | default(consul_client_address, true) }}" https: "{{ consul_addresses_https | default(consul_client_address, true) }}" rpc: "{{ consul_addresses_rpc | default(consul_client_address, true) }}" grpc: "{{ consul_addresses_grpc | default(consul_client_address, true) }}" grpc_tls: "{{ consul_addresses_grpc_tls | default(consul_client_address, true) }}"
- The official documentation on the Ports Used
- The ports mapping is a nested dict object that allows setting the bind ports for the following keys:
- dns - The DNS server, -1 to disable. Default 8600.
- http - The HTTP API, -1 to disable. Default 8500.
- https - The HTTPS API, -1 to disable. Default -1 (disabled).
- rpc - The CLI RPC endpoint. Default 8400. This is deprecated in Consul 0.8 and later.
- grpc - The gRPC endpoint, -1 to disable. Default -1 (disabled).
- grpc_tls - The gRPC TLS endpoint, -1 to disable. Default -1 (disabled). This is available in Consul 1.14.0 and later.
- serf_lan - The Serf LAN port. Default 8301.
- serf_wan - The Serf WAN port. Default 8302.
- server - Server RPC address. Default 8300.
For example, to enable the consul HTTPS API it is possible to set the variable as follows:
- Default values:
consul_ports:
dns: "{{ consul_ports_dns | default('8600', true) }}"
http: "{{ consul_ports_http | default('8500', true) }}"
https: "{{ consul_ports_https | default('-1', true) }}"
rpc: "{{ consul_ports_rpc | default('8400', true) }}"
serf_lan: "{{ consul_ports_serf_lan | default('8301', true) }}"
serf_wan: "{{ consul_ports_serf_wan | default('8302', true) }}"
server: "{{ consul_ports_server | default('8300', true) }}"
grpc: "{{ consul_ports_grpc | default('-1', true) }}"
grpc_tls: "{{ consul_ports_grpc_tls | default('-1', true) }}"
Notice that the dict object has to use precisely the names stated in the documentation! And all ports must be specified. Overwriting one or multiple ports can be done using the consul_ports_*
variables.
- Define a custom node name (should not include dots)
See node_name
- The default value on Consul is the hostname of the server.
- Default value: ''
- List of upstream DNS servers
See recursors
- Override with
CONSUL_RECURSORS
environment variable
- Override with
- Default value: Empty list
- Whether to enable iptables rules for DNS forwarding to Consul
- Override with
CONSUL_IPTABLES_ENABLE
environment variable
- Override with
- Default value: false
- Add basic ACL config file
- Override with
CONSUL_ACL_POLICY
environment variable
- Override with
- Default value: false
- Enable ACLs
- Override with
CONSUL_ACL_ENABLE
environment variable
- Override with
- Default value: false
- TTL for ACL's
- Override with
CONSUL_ACL_TTL
environment variable
- Override with
- Default value: 30s
- Define if tokens set using the API will be persisted to disk or not
- Override with
CONSUL_ACL_TOKEN_PERSISTENCE
environment variable
- Override with
- Default value: true
- ACL authoritative datacenter name
- Override with
CONSUL_ACL_DATACENTER
environment variable
- Override with
- Default value:
{{ consul_datacenter }}
(dc1
)
- Default ACL down policy
- Override with
CONSUL_ACL_DOWN_POLICY
environment variable
- Override with
- Default value: allow
- Default ACL token, only set if provided
- Override with
CONSUL_ACL_TOKEN
environment variable
- Override with
- Default value: ''
- Used for clients and servers to perform internal operations to the service catalog. See: acl_agent_token
- Override with
CONSUL_ACL_AGENT_TOKEN
environment variable
- Override with
- Default value: ''
- A special access token that has agent ACL policy write privileges on each agent where it is configured
- Override with
CONSUL_ACL_AGENT_MASTER_TOKEN
environment variable
- Override with
- Default value: ''
- Default ACL policy
- Override with
CONSUL_ACL_DEFAULT_POLICY
environment variable
- Override with
- Default value: allow
- ACL master token
- Override with
CONSUL_ACL_MASTER_TOKEN
environment variable
- Override with
- Default value: UUID
- Display generated ACL Master Token
- Override with
CONSUL_ACL_MASTER_TOKEN_DISPLAY
environment variable
- Override with
- Default value: false
- Enable ACL replication without token (makes it possible to set the token
trough the API)
- Override with
CONSUL_ACL_REPLICATION_TOKEN_ENABLE
environment variable
- Override with
- Default value: ''
- ACL replication token
- Override with
CONSUL_ACL_REPLICATION_TOKEN_DISPLAY
environment variable
- Override with
- Default value: SN4K3OILSN4K3OILSN4K3OILSN4K3OIL
- Enable TLS
- Override with
CONSUL_ACL_TLS_ENABLE
environment variable
- Override with
- Default value: false
- Enables or disables the management of the TLS files
- Disable it if you enable TLS (
consul_tls_enable
) but want to manage the TLS files on your own
- Disable it if you enable TLS (
- Default value: true
- Target directory for TLS files
- Override with
CONSUL_TLS_DIR
environment variable
- Override with
- Default value:
/etc/consul/ssl
- CA certificate filename
- Override with
CONSUL_TLS_CA_CRT
environment variable
- Override with
- Default value:
ca.crt
- Server certificate
- Override with
CONSUL_TLS_SERVER_CRT
environment variable
- Override with
- Default value:
server.crt
- Server key
- Override with
CONSUL_TLS_SERVER_KEY
environment variable
- Override with
- Default value:
server.key
- Copy from remote source if TLS files are already on host
- Default value: false
- Enable Gossip Encryption
- Default value: true
- Verify incoming Gossip connections
- Default value: true
- Verify outgoing Gossip connections
- Default value: true
- If set, the keyring will not be persisted to a file. Any installed keys will be lost on shutdown, and only the given -encrypt key will be available on startup.
- Default value: false
- Set the encryption key; should be the same across a cluster. If not present the key will be generated & retrieved from the bootstrapped server.
- Default value: ''
- Verify incoming connections
- Override with
CONSUL_TLS_VERIFY_INCOMING
environment variable
- Override with
- Default value: false
- Verify outgoing connections
- Override with
CONSUL_TLS_VERIFY_OUTGOING
environment variable
- Override with
- Default value: true
- Verify incoming connections on RPC endpoints (client certificates)
- Override with
CONSUL_TLS_VERIFY_INCOMING_RPC
environment variable
- Override with
- Default value: false
- Verify incoming connections on HTTPS endpoints (client certificates)
- Override with
CONSUL_TLS_VERIFY_INCOMING_HTTPS
environment variable
- Override with
- Default value: false
- Verify server hostname
- Override with
CONSUL_TLS_VERIFY_SERVER_HOSTNAME
environment variable
- Override with
- Default value: false
- Minimum acceptable TLS version
- Can be overridden with
CONSUL_TLS_MIN_VERSION
environment variable - For versions < 1.12.0 use 'tls12,tls13,...'
- Can be overridden with
- Default value: TLSv1_2
- Comma-separated list of supported ciphersuites
- Default value: ""
- Prefer server's cipher suite over client cipher suite
- Can be overridden with
CONSUL_TLS_PREFER_SERVER_CIPHER_SUITES
environment variable
- Can be overridden with
- Default value: false
- Auto encrypt
- Default value:
auto_encrypt:
enabled: false
- Example:
auto_encrypt:
enabled: true
dns_san: ["consul.com"]
ip_san: ["127.0.0.1"]
- If true, then always install consul. Otherwise, consul will only be installed either if
not present on the host, or if the installed version differs from
consul_version
. - The role does not handle the orchestration of a rolling update of servers followed by client nodes
- Default value: false
- Whether to download the files for installation directly on the remote hosts
- This is the only option on Windows as WinRM is somewhat limited in this scope
- Default value: false
- Boolean, whether to install consul from repository as opposed to installing the binary directly.
- Supported distros: Alma Linux, Amazon Linux, CentOS, Debian, Fedora, Ubuntu, Red Hat, Rocky.
- Default value: false
- Enable the consul ui?
- Default value: true
- Enable legacy consul ui mode
- Default value: false
- Disable the consul update check?
- Default value: false
- Enable script based checks?
- Default value: false
- This is discouraged in favor of
consul_enable_local_script_checks
.
- Enable locally defined script checks?
- Default value: false
- Raft protocol to use.
- Default value:
- Consul versions <= 0.7.0: 1
- Consul versions > 0.7.0: 3
- The Consul role of the node, one of: bootstrap, server, or client
- Default value: client
One server should be designated as the bootstrap server, and the other servers will connect to this server. You can also specify client as the role, and Consul will be configured as a client agent instead of a server.
There are two methods to setup a cluster, the first one is to explicitly choose the bootstrap server, the other one is to let the servers elect a leader among themselves.
Here is an example of how the hosts inventory could be defined for a simple cluster of 3 servers, the first one being the designated bootstrap / leader:
[consul_instances]
consul1.consul consul_node_role=bootstrap
consul2.consul consul_node_role=server
consul3.consul consul_node_role=server
consul4.local consul_node_role=client
Or you can use the simpler method of letting them do their election process:
[consul_instances]
consul1.consul consul_node_role=server consul_bootstrap_expect=true
consul2.consul consul_node_role=server consul_bootstrap_expect=true
consul3.consul consul_node_role=server consul_bootstrap_expect=true
consul4.local consul_node_role=client
Note that this second form is the preferred one, because it is simpler.
Autopilot is a set of new features added in Consul 0.8 to allow for automatic operator-friendly management of Consul servers. It includes cleanup of dead servers, monitoring the state of the Raft cluster, and stable server introduction.
https://www.consul.io/docs/guides/autopilot.html
- Enable Autopilot config (will be written to bootsrapper node)
- Override with
CONSUL_AUTOPILOT_ENABLE
environment variable
- Override with
- Default value: false
Dead servers will periodically be cleaned up and removed from the Raft peer set, to prevent them from interfering with the quorum size and leader elections. This cleanup will also happen whenever a new server is successfully added to the cluster.
- Enable Autopilot config (will be written to bootsrapper node)
- Override with
CONSUL_AUTOPILOT_CLEANUP_DEAD_SERVERS
environment variable
- Override with
- Default value: false
Used in the serf health check to determine node health.
- Sets the threshold for time since last contact
- Override with
CONSUL_AUTOPILOT_LAST_CONTACT_THRESHOLD
environment variable
- Override with
- Default value: 200ms
- Used in the serf health check to set a max-number of log entries nodes can trail the leader
- Override with
CONSUL_AUTOPILOT_MAX_TRAILING_LOGS
environment variable
- Override with
- Default value: 250
- Time to allow a new node to stabilize
- Override with
CONSUL_AUTOPILOT_SERVER_STABILIZATION_TIME
environment variable
- Override with
- Default value: 10s
Consul Enterprise Only (requires that CONSUL_ENTERPRISE is set to true)
- Override with
CONSUL_AUTOPILOT_REDUNDANCY_ZONE_TAG
environment variable - Default value: az
Consul Enterprise Only (requires that CONSUL_ENTERPRISE is set to true)
- Override with
CONSUL_AUTOPILOT_DISABLE_UPGRADE_MIGRATION
environment variable - Default value: false
Consul Enterprise Only (requires that CONSUL_ENTERPRISE is set to true)
- Override with
CONSUL_AUTOPILOT_UPGRADE_VERSION_TAG
environment variable - Default value: ''
- Enables the generation of additional config files in the Consul config directory for debug purpose
- Default value: false
- If the default config template does not suit your needs, you can replace it with your own.
- Default value:
templates/config.json.j2
.
As Consul loads the configuration from files and directories in lexical order, typically merging on top of previously parsed configuration files, you may set custom configurations via consul_config_custom
, which will be expanded into a file named config_z_custom.json
within your consul_config_path
which will be loaded after all other configuration by default.
An example usage for enabling telemetry
:
vars:
consul_config_custom:
telemetry:
dogstatsd_addr: "localhost:8125"
dogstatsd_tags:
- "security"
- "compliance"
disable_hostname: true
Consul snapshot agent takes backup snaps on a set interval and stores them. Must have enterprise
- Bool, true will setup and start snapshot agent (enterprise only)
- Default value: false
- Location snapshots will be stored. NOTE: path must end in snaps
- Default value:
{{ consul_config_path }}/snaps
- Default value: 1h
The consul
binary works on most Linux platforms and is not distribution
specific. However, some distributions require installation of specific OS
packages with different package names.
- Consul package filename
- Default value:
{{ consul_version }}_linux_amd64.zip
- Consul package download URL
- Default value:
{{ consul_zip_url }}
- Consul download SHA256 summary
- Default value: SHA256 summary
- List of OS packages to install
- Default value: list
- Consul package filename
- Default value:
{{ consul_version }}_linux_amd64.zip
- Consul package download URL
- Default value:
{{ consul_zip_url }}
- Consul download SHA256 summary
- Default value: SHA256 SUM
- List of OS packages to install
- Default value: list
- Consul package filename
- Default value:
{{ consul_version }}_linux_amd64.zip
- Consul package download URL
- Default value:
{{ consul_zip_url }}
- Consul download SHA256 summary
- Default value: SHA256 summary
- List of OS packages to install
- Default value: list
- Integer value for systemd unit
RestartSec
option - Default value: 42
- Integer value for systemd unit
LimitNOFILE
option - Default value: 65536
- String value for systemd unit
Restart
option - Default value:
on-failure
- Consul package filename
- Default value:
{{ consul_version }}_linux_amd64.zip
- Consul package download URL
- Default value:
{{ consul_zip_url }}
- Consul download SHA256 summary
- Default value: SHA256 summary
- List of OS packages to install
- Default value: list
- Consul package filename
- Default value:
{{ consul_version }}_windows_amd64.zip
- Consul package download URL
- Default value:
{{ consul_zip_url }}
- Consul download SHA256 summary
- Default value: SHA256 summary
- List of OS packages to install
- Default value: list
- List of Consul performance tuning items
- Default value: list
- Raft multiplier scales key Raft timing parameters
- Default value: 1
-
Node leave drain time is the dwell time for a server to honor requests while gracefully leaving
-
Default value: 5s
- RPC hold timeout is the duration that a client or server will retry internal RPC requests during leader elections
- Default value: 7s
- leave_on_terminate If enabled, when the agent receives a TERM signal, it will send a Leave message to the rest of the cluster and gracefully leave. The default behavior for this feature varies based on whether or not the agent is running as a client or a server. On agents in client-mode, this defaults to true and for agents in server-mode, this defaults to false.
- Consul node limits (key-value)
- Supported in Consul version 0.9.3 or later
- Default value: {}
- Example:
consul_limits:
http_max_conns_per_client: 250
rpc_max_conns_per_client: 150
Ansible requires GNU tar and this role performs some local use of the unarchive module for efficiency, so ensure that your system has gtar
and unzip
installed and in the PATH. If you don't this role will install unzip
on the remote machines to unarchive the ZIP files.
If you're on system with a different (i.e. BSD) tar
, like macOS and you see odd errors during unarchive tasks, you could be missing gtar
.
Installing Ansible on Windows requires the PowerShell Community Extensions. These already installed on Windows Server 2012 R2 and onward. If you're attempting this role on Windows Server 2008 or earlier, you'll want to install the extensions here.
Basic installation is possible using the included site.yml
playbook:
ansible-playbook -i hosts site.yml
You can also pass variables in using the --extra-vars
option to the
ansible-playbook
command:
ansible-playbook -i hosts site.yml --extra-vars "consul_datacenter=maui"
Be aware that for clustering, the included site.yml
does the following:
- Executes consul role (installs Consul and bootstraps cluster)
- Reconfigures bootstrap node to run without bootstrap-expect setting
- Restarts bootstrap node
Basic support for ACLs is included in the role. You can set the environment variables CONSUL_ACL_ENABLE
to true, and also set the CONSUL_ACL_DATACENTER
environment variable to its correct value for your environment prior to executing your playbook; for example:
CONSUL_ACL_ENABLE=true CONSUL_ACL_DATACENTER=maui \
CONSUL_ACL_MASTER_TOKEN_DISPLAY=true ansible-playbook -i uat_hosts aloha.yml
If you want the automatically generated ACL Master Token value emitted to standard out during the play, set the environment variable CONSUL_ACL_MASTER_TOKEN_DISPLAY
to true as in the above example.
If you want to use existing tokens, set the environment variables CONSUL_ACL_MASTER_TOKEN
and CONSUL_ACL_REPLICATION_TOKEN
as well, for example:
CONSUL_ACL_ENABLE=true CONSUL_ACL_DATACENTER=stjohn \
CONSUL_ACL_MASTER_TOKEN=0815C55B-3AD2-4C1B-BE9B-715CAAE3A4B2 \
CONSUL_ACL_REPLICATION_TOKEN=C609E56E-DD0B-4B99-A0AD-B079252354A0 \
CONSUL_ACL_MASTER_TOKEN_DISPLAY=true ansible-playbook -i uat_hosts sail.yml
There are a number of Ansible ACL variables you can override to further refine your initial ACL setup. They are not all currently picked up from environment variables, but do have some sensible defaults.
Check defaults/main.yml
to see how some of he defaults (i.e. tokens) are automatically generated.
The role now includes support for DNS forwarding with Dnsmasq.
Enable like this:
ansible-playbook -i hosts site.yml --extra-vars "consul_dnsmasq_enable=true"
Then, you can query any of the agents via DNS directly via port 53, for example:
dig @consul1.consul consul3.node.consul
; <<>> DiG 9.8.3-P1 <<>> @consul1.consul consul3.node.consul
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 29196
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;consul3.node.consul. IN A
;; ANSWER SECTION:
consul3.node.consul. 0 IN A 10.1.42.230
;; Query time: 42 msec
;; SERVER: 10.1.42.210#53(10.1.42.210)
;; WHEN: Sun Aug 7 18:06:32 2016
;;
- Whether to delegate Consul datacenter DNS domain to Consul
- Default value: false
- Whether to install and configure DNS API forwarding on port 53 using DNSMasq
- Override with
CONSUL_DNSMASQ_ENABLE
environment variable
- Override with
- Default value: false
- Setting this option to true prevents DNSmasq from binding by default 0.0.0.0, but instead instructs it to bind to the specific network interfaces that correspond to the
consul_dnsmasq_listen_addresses
option - Default value: false
- Address used by DNSmasq to query consul
- Default value:
consul_address.dns
- Defaults to 127.0.0.1 if consul's DNS is bound to all interfaces (eg
0.0.0.0
)
- dnsmasq cache-size
- If smaller then 0, the default dnsmasq setting will be used.
- Default value: -1
- Upstream DNS servers used by dnsmasq
- Default value: 8.8.8.8 and 8.8.4.4
- Reverse lookup subnets
- Default value: []
- Do not poll /etc/resolv.conf
- Default value: false
- Ignore /etc/resolv.conf file
- Default value: false
- Only allow requests from local subnets
- Default value: false
- Custom list of addresses to listen on.
- Default value: []
- Enable Consul Connect feature
- Default value: false
- List of files to ignore during cleanup steps
- Default value: [{{ consul_configd_path }}/consul.env]
This role can also use iptables instead of Dnsmasq for forwarding DNS queries to Consul. You can enable it like this:
ansible-playbook -i hosts site.yml --extra-vars "consul_iptables_enable=true"
Note that iptables forwarding and DNSmasq forwarding cannot be used simultaneously and the execution of the role will stop with error if such a configuration is specified.
You can enable TLS encryption by dropping a CA certificate, server certificate, and server key into the role's files
directory.
By default these are named:
ca.crt
(can be overridden by {{ consul_tls_ca_crt }})server.crt
(can be overridden by {{ consul_tls_server_crt }})server.key
(can be overridden by {{ consul_tls_server_key }})
Then either set the environment variable CONSUL_TLS_ENABLE=true
or use the Ansible variable consul_tls_enable=true
at role runtime.
You can create a configuration file for consul services.
Add a list of service in the consul_services
.
name | Required | Type | Default | Comment |
---|---|---|---|---|
consul_services | False | List | [] |
List of service object (see below) |
Services object:
name | Required | Type | Default | Comment |
---|---|---|---|---|
name | True | string | Name of the service | |
id | False | string | Id of the service | |
tags | False | list | List of string tags | |
address | False | string | service-specific IP address | |
meta | False | dict | Dict of 64 key/values with string semantics | |
port | False | int | Port of the service | |
enable_tag_override | False | bool | enable/disable the anti-entropy feature for the service | |
kind | False | string | identify the service as a Connect proxy instance | |
proxy | False | dict | proxy configuration | |
checks | False | list | List of checks configuration | |
connect | False | dict | Connect object configuration | |
weights | False | dict | Weight of a service in DNS SRV responses | |
token | False | string | ACL token to use to register this service |
Configuration example:
consul_services:
- name: "openshift"
tags: ['production']
- name: "redis"
id: "redis"
tags: ['primary']
address: ""
meta:
meta: "for my service"
proxy:
destination_service_name: "redis"
destination_service_id: "redis1"
local_service_address: "127.0.0.1"
local_service_port: 9090
config: {}
upstreams: []
checks:
- args: ["/home/consul/check.sh"]
interval: "10s"
Then you can check that the service is well added to the catalog
> consul catalog services
consul
openshift
redis
Note: to delete a service that has been added from this role, remove it from the
consul_services
list and apply the role again.
See examples/README_VAGRANT.md for details on quick Vagrant deployments under VirtualBox for development, evaluation, testing, etc.
BSD
Special thanks to the folks listed in CONTRIBUTORS.md for their contributions to this project.
Contributions are welcome, provided that you can agree to the terms outlined in CONTRIBUTING.md.