• Stars
    star
    191
  • Rank 202,877 (Top 4 %)
  • Language
    Ruby
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Development repository for the consul cookbook

Consul Cookbook

Cookbook Version CI State OpenCollective OpenCollective License

[Application cookbook][0] which installs and configures Consul.

Consul is a tool for discovering and configuring services within your infrastructure. This is an application cookbook which takes a simplified approach to configuring and installing Consul. Additionally, it provides Chef primitives for more advanced configuration.

Maintainers

This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org or come chat with us on the Chef Community Slack in #sous-chefs.

Basic Usage

For most infrastructure we suggest first starting with the default recipe. This installs and configures Consul from the latest supported release. It is also what is used to certify platform support through the use of our integration tests.

This cookbook provides node attributes which are used to fine tune the default recipe which installs and configures Consul. These values are passed directly into the Chef resource/providers which are exposed for more advanced configuration.

Out of the box the following platforms are certified to work and are tested using our Test Kitchen configuration. Additional platforms may work, but your mileage may vary.

  • RHEL/CentOS 7 & 8
  • Ubuntu 16.04, 18.04 & 20.04
  • Debian 9 & 10
  • Windows Server 2012 R2

Client

Out of the box the default recipe installs and configures the Consul agent to run as a service in client mode. The intent here is that your infrastructure already has a quorum of servers. In order to configure Consul to connect to your cluster you would supply an array of addresses for the Consul agent to join. This would be done in your [wrapper cookbook][2]:

node.default['consul']['config']['start_join'] = %w{c1.internal.corporate.com c2.internal.corporate.com c3.internal.corporate.com}

Server

This cookbook is designed to allow for the flexibility to bootstrap a new cluster. The best way to do this is through the use of a [wrapper cookbook][2] which tunes specific node attributes for a production server deployment.

The Consul cluster cookbook is provided as an example.

Advanced Usage

As explained above this cookbook provides Chef primitives in the form of resource/provider to further manage the install and configuration of Consul. These primitives are what is used in the default recipe, and should be used in your own [wrapper cookbooks][2] for more advanced configurations.

Configuration

It is very important to understand that each resource/provider has defaults for some properties. Any changes to a resource's default properties may need to be also changed in other resources. The best example is the Consul configuration directory.

In the example below we're going to change the configuration file from the default (/etc/consul.json) to one that may be on a special volume. It is obvious that we need to change the path where consul_config writes its file to, but it is less obvious that this needs to be passed into consul_service.

Inside of a recipe in your [wrapper cookbook][2] you'll want to do something like the following block of code. It uses the validated input from the configuration resource and passes it into the service resource. This ensures that we're using the same data.

config = consul_config '/data/consul/default.json'
consul_service 'consul' do
  config_file config.path
end

Security

The default recipe makes the Consul configuration writable by the consul service user to avoid breaking existing implementations. You can make this more secure by setting the node['consul']['config']['owner'] attribute to root, or set the owner property of consul_config explicitly:

# attributes file
default['consul']['config']['owner'] = 'root'

or

# recipe file
consul_config '/etc/consul/consul.json' do
  owner 'root'
end

Watches/Definitions

In order to provide an idempotent implementation of Consul watches and definitions. We write these out as a separate configuration file in the JSON file format. The provider for both of these resources are identical in functionality.

Below is an example of writing a [Consul service definition][10] for the master instance of Redis. We pass in several parameters and tell the resource to notify the proper instance of the Consul service to reload.

consul_definition 'redis' do
  type 'service'
  parameters(tags: %w{master}, address: '127.0.0.1', port: 6379)
  notifies :reload, 'consul_service[consul]', :delayed
end

A [check definition][11] can easily be added as well. You simply have to change the type and pass in the correct parameters. The definition below checks memory utilization using a script on a ten second interval.

consul_definition 'mem-util' do
  type 'check'
  parameters(script: '/usr/local/bin/check_mem.py', interval: '10s')
  notifies :reload, 'consul_service[consul]', :delayed
end

A service definition with an integrated check can also be created. You will have to define a regular service and then add a check as a an additional parameter. The definition below checks if the vault service is healthy on a 10 second interval and 5 second timeout.

consul_definition 'vault' do
  type 'service'
  parameters(
    port:  8200,
    address: '127.0.0.1',
    tags: ['vault', 'http'],
    check: {
      interval: '10s',
      timeout: '5s',
      http: 'http://127.0.0.1:8200/v1/sys/health'
    }
  )
  notifies :reload, 'consul_service[consul]', :delayed
end

Finally, a [watch][9] is created below to tell the agent to monitor to see if an application has been deployed. Once that application is deployed a script is run locally. This can be used, for example, as a lazy way to clear a HTTP disk cache.

consul_watch 'app-deploy' do
  type 'event'
  parameters(handler: '/usr/local/bin/clear-disk-cache.sh')
  notifies :reload, 'consul_service[consul]', :delayed
end

A keen eye would notice that we are delaying the reload of the Consul service instance. The reason we do this is to minimize the number of times we need to tell Consul to actually reload configurations. If there are several definitions this may save a little time off your Chef run.

ACLs

The consul_acl resource allows management of [Consul ACL rules][15]. Supported actions are :create and :delete. The :create action will update/insert as necessary.

The consul_acl resource requires the Diplomat Ruby API gem to be installed and available to Chef before using the resource. This can be accomplished by including consul::client_gem recipe in your run list. If you are using Chef Infra Client 15.8+ you will need to make sure you are using at least version 2.2.6 of the diplomat gem.

In order to make the resource idempotent and only notify when necessary, the id field is always required (defaults to the name of the resource). If type is not provided, it will default to "client". The acl_name and rules attributes are also optional; if not included they will be empty in the resulting ACL.

The example below will create a client ACL token with an ID of the given UUID, Name of "AwesomeApp Token", and Rules of the given string.

consul_acl '49f06aa9-782f-465a-becf-44f0aaefd335' do
  acl_name 'AwesomeApp Token'
  type 'client'
  rules <<-EOS.gsub(/^\s{4}/, '')
    key "" {
      policy = "read"
    }
    service "" {
      policy = "write"
    }
  EOS
  auth_token node['consul']['config']['acl_master_token']
end

Execute

The command-line agent provides a mechanism to facilitate remote execution. For example, this can be used to run the uptime command across your fleet of nodes which are hosting a particular API service.

consul_execute 'uptime' do
  options(service: 'api')
end

Warning on git based installs

Consul v1.0 states that Go 1.9 is a requirement. The default go installation uses 1.5, so you may need to override a ['go']['version'] attribute to allow the git installation to work reliably.

All of the [options available on the command-line][12] can be passed into the resource. This could potentially be a very dangerous operation. You should absolutely understand what you are doing. By the nature of this command it is impossible for it to be idempotent.

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers!

https://opencollective.com/sous-chefs#backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

https://opencollective.com/sous-chefs/sponsor/0/website https://opencollective.com/sous-chefs/sponsor/1/website https://opencollective.com/sous-chefs/sponsor/2/website https://opencollective.com/sous-chefs/sponsor/3/website https://opencollective.com/sous-chefs/sponsor/4/website https://opencollective.com/sous-chefs/sponsor/5/website https://opencollective.com/sous-chefs/sponsor/6/website https://opencollective.com/sous-chefs/sponsor/7/website https://opencollective.com/sous-chefs/sponsor/8/website https://opencollective.com/sous-chefs/sponsor/9/website

More Repositories

1

docker

Development repository for the docker cookbook
Ruby
1,348
star
2

elasticsearch

Development repository for the elasticsearch cookbook
Ruby
882
star
3

aws

Development repository for the aws cookbook
Ruby
594
star
4

nginx

Development repository for the nginx cookbook
Ruby
551
star
5

rvm

Development repository for the rvm cookbook
Ruby
516
star
6

php

Development repository for the php cookbook
HTML
445
star
7

jenkins

Development repository for the jenkins cookbook
Ruby
424
star
8

java

Development repository for the java cookbook
Ruby
397
star
9

postgresql

Development repository for the postgresql cookbook
Ruby
357
star
10

mysql

Development repository for the mysql cookbook
Ruby
336
star
11

ruby_rbenv

Development repository for the ruby_rbenv cookbook
Ruby
332
star
12

redisio

Development repository for the redisio cookbook
HTML
297
star
13

apache2

Development repository for the apache2 cookbook
Ruby
282
star
14

nodejs

Development repository for the nodejs cookbook
Ruby
228
star
15

apt

Development repository for the apt cookbook
Ruby
203
star
16

haproxy

Development repository for the haproxy cookbook
Ruby
156
star
17

graphite

Development repository for the graphite cookbook
Ruby
154
star
18

homebrew

Development repository for the homebrew cookbook
Ruby
151
star
19

users

Development repository for the users cookbook
Ruby
138
star
20

nagios

Development repository for the nagios cookbook
Ruby
125
star
21

ruby_build

Development repository for the ruby_build cookbook
Ruby
123
star
22

git

Development repository for the git cookbook
Ruby
123
star
23

logrotate

Development repository for the logrotate cookbook
Ruby
122
star
24

percona

Development repository for the percona cookbook
Ruby
117
star
25

openssh

Development repository for the openssh cookbook
Ruby
114
star
26

powershell

Development repository for the powershell cookbook
Ruby
110
star
27

postfix

Development repository for the postfix cookbook
Ruby
103
star
28

tomcat

Development repository for the tomcat cookbook
Ruby
99
star
29

openvpn

Development repository for the openvpn cookbook
Ruby
98
star
30

ark

Development repository for the ark cookbook
Ruby
98
star
31

line

Development repository for the line cookbook
Ruby
97
star
32

firewall

Development repository for the firewall cookbook
Ruby
95
star
33

yum

Development repository for the yum cookbook
Ruby
95
star
34

kafka

Development repository for the kafka cookbook
Ruby
91
star
35

erlang

Development repository for the erlang cookbook
Ruby
87
star
36

sublimechef

A Sublime Text 2 Package for authoring Chef related files
84
star
37

iis

Development repository for the iis cookbook
Ruby
82
star
38

etcd

Development repository for the etcd cookbook
Ruby
79
star
39

cron

Development repository for the cron cookbook
Ruby
77
star
40

grafana

Development repository for the grafana cookbook
Ruby
76
star
41

chef-splunk

Development repository for the chef-splunk cookbook
Ruby
76
star
42

sc-mongodb

Development repository for the sc-mongodb cookbook
Ruby
75
star
43

certificate

Development repository for the certificate cookbook
Ruby
73
star
44

ntp

Development repository for the ntp cookbook
Ruby
68
star
45

rsyslog

Development repository for the rsyslog cookbook
Ruby
65
star
46

sql_server

Development repository for the sql_server cookbook
Ruby
63
star
47

fail2ban

Development repository for the fail2ban cookbook
Ruby
58
star
48

selinux

Development repository for the selinux cookbook
Ruby
58
star
49

windows_ad

Development repository for the windows_ad cookbook
Ruby
58
star
50

vagrant

Development repository for the vagrant cookbook
Ruby
57
star
51

varnish

Development repository for the varnish cookbook
Ruby
56
star
52

lvm

Development repository for the lvm cookbook
Ruby
56
star
53

perl

Development repository for the perl cookbook
Ruby
52
star
54

golang

Development repository for the golang cookbook
Ruby
50
star
55

memcached

Development repository for the memcached cookbook
Ruby
49
star
56

mariadb

Development repository for the mariadb cookbook
Ruby
48
star
57

hashicorp-vault

Development repository for the hashicorp-vault cookbook
Ruby
46
star
58

rundeck

Development repository for the rundeck cookbook
Ruby
46
star
59

ossec

Development repository for the ossec cookbook
Ruby
44
star
60

ufw

Development repository for the ufw cookbook
Ruby
44
star
61

confluence

Development repository for the confluence cookbook
Ruby
43
star
62

openldap

Development repository for the openldap cookbook
Ruby
42
star
63

nfs

Development repository for the nfs cookbook
Ruby
40
star
64

kubernetes

Development repository for the kubernetes cookbook
Ruby
39
star
65

vim

Development repository for the vim cookbook
Ruby
38
star
66

maven

Development repository for the maven cookbook
Ruby
36
star
67

bind

Development repository for the bind cookbook
Ruby
36
star
68

passenger_apache2

Development repository for the passenger_apache2 cookbook
Ruby
36
star
69

keepalived

Development repository for the keepalived cookbook
Ruby
33
star
70

aptly

Development repository for the aptly cookbook
Ruby
31
star
71

samba

Development repository for the samba cookbook
Ruby
30
star
72

resolver

Development repository for the resolver cookbook
Ruby
28
star
73

squid

Development repository for the squid cookbook
Ruby
28
star
74

snort

Development repository for the snort cookbook
Ruby
27
star
75

pyenv

Development repository for the pyenv cookbook
Ruby
27
star
76

freebsd

Development repository for the freebsd cookbook
Ruby
27
star
77

dhcp

Development repository for the dhcp cookbook
Ruby
27
star
78

nrpe

Development repository for the nrpe cookbook
Ruby
25
star
79

rsync

Development repository for the rsync cookbook
Ruby
24
star
80

github

Development repository for the github cookbook
Ruby
24
star
81

filesystem

Development repository for the filesystem cookbook
Ruby
24
star
82

yum-epel

Development repository for the yum-epel cookbook
Ruby
23
star
83

network_interfaces

Development repository for the network_interfaces cookbook
Ruby
23
star
84

drbd

Development repository for the drbd cookbook
Ruby
19
star
85

djbdns

Development repository for the djbdns cookbook
Ruby
19
star
86

sssd_ldap

Development repository for the sssd_ldap cookbook
Ruby
18
star
87

dpkg_autostart

Development repository for the dpkg_autostart cookbook
Ruby
18
star
88

packagecloud

Development repository for the packagecloud cookbook
Ruby
17
star
89

webpi

Development repository for the webpi cookbook
Ruby
17
star
90

gems

Development repository for the gems cookbook
Ruby
17
star
91

language-chef

Development repository for the language-chef plugin for the Atom text editor
JavaScript
17
star
92

elixir

Development repository for the elixir cookbook
Ruby
17
star
93

htpasswd

Development repository for the htpasswd cookbook
Ruby
15
star
94

stunnel

Development repository for the stunnel cookbook
Ruby
14
star
95

apparmor

Development repository for the apparmor cookbook
Ruby
14
star
96

smartmontools

Development repository for the smartmontools cookbook
HTML
13
star
97

transmission

Development repository for the transmission cookbook
Ruby
13
star
98

gpg

Development repository for the gpg cookbook
Ruby
12
star
99

wix

Development repository for the wix cookbook
Ruby
12
star
100

tftp

Development repository for the tftp cookbook
Ruby
11
star