cmacrae.consul
Consul
[](https://travis-ci.org/cmacrae/ansible-consul) A straightforward Ansible role for deploying and setting up [Consul](https://consul.io).Features
Configure Consul with YAML
You can set up Consul using YAML, which will be converted to JSON. Here’s an example of a configuration:
consul_master_token: myToken
consul_server: true
consul_configs:
main:
acl_datacenter: pantheon
acl_master_token: "{{ consul_master_token | to_uuid }}"
bootstrap: true
bind_addr: 0.0.0.0
client_addr: 0.0.0.0
datacenter: pantheon
data_dir: "{{ consul_data_dir }}"
log_level: INFO
node_name: master
server: "{{ consul_server }}"
ui: true
This role doesn't come with preset configurations. Instead of writing your Consul settings in JSON, you can write them in YAML which is easier to manage. The example shows how you can use Ansible's features to create dynamic values in your configuration.
Multiple Configuration Files
In the example above, the consul_configs
variable has a main
dictionary. You can create multiple dictionaries for different configurations. These will be saved under separate files in the conf.d
directory.
Keep It Simple (KISS)
While it may not seem like a feature, simplicity is valuable. Configuring Consul is easy, and this Ansible role reflects that. The main tasks file is just over 70 lines long, and the main configuration template is only 1 line. This keeps the role flexible and easy to integrate with other setups.
Packer Support
This role allows setting consul_packer_provision
to true
(it defaults to false
). When set to true
, the Consul service won't start during the Ansible run. This is helpful when you're preparing machine images with Packer, where certain values might be placeholders.
Requirements
This role has been tested on Ubuntu 16.04, but it should work on any Linux distribution that uses systemd
and has the unzip
package.
Default Role Variables
consul_group_name: consul
consul_group_gid: 3000
consul_user_name: consul
consul_user_uid: 3000
consul_user_home: /opt/consul
consul_config_dir: "{{ consul_user_home }}/conf.d"
consul_data_dir: "{{ consul_user_home }}/data"
consul_version: 0.8.4
consul_server: false
consul_uri: "https://releases.hashicorp.com/consul/{{ consul_version }}/consul_{{ consul_version }}_linux_amd64.zip"
consul_config_src: main.json.j2
consul_service_file:
src: consul.service.j2
dest: /etc/systemd/system/consul.service
consul_config:
datacenter: dc-1
data_dir: "{{ consul_data_dir }}"
log_level: INFO
node_name: node-1
server: "{{ consul_server }}"
Example Playbook
- hosts: consul_servers
vars:
consul_master_token: myToken
consul_server: true
consul_config:
acl_datacenter: pantheon
acl_master_token: "{{ consul_master_token | to_uuid }}"
bootstrap: true
bind_addr: 0.0.0.0
client_addr: 0.0.0.0
datacenter: pantheon
data_dir: "{{ consul_data_dir }}"
log_level: INFO
node_name: master
server: "{{ consul_server }}"
ui: true
roles:
- cmacrae.consul
License
MIT
Author Information
Created by Calum MacRae
Feel free to:
- Contact me: @calumacrae, [email protected]
- Report an issue
- Contribute
ansible-galaxy install cmacrae.consul