Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include example of automatic bootstrapping #169

Open
trevorr opened this issue Aug 18, 2016 · 1 comment
Open

Include example of automatic bootstrapping #169

trevorr opened this issue Aug 18, 2016 · 1 comment

Comments

@trevorr
Copy link
Contributor

trevorr commented Aug 18, 2016

https://www.consul.io/docs/guides/bootstrapping.html:

In versions of Consul prior to 0.4, bootstrapping was a more manual process. [...] Manual bootstrapping is not recommended as it is more error-prone than automatic bootstrapping with -bootstrap-expect.

The examples currently only show manual bootstrapping, and neglect to mention that the -bootstrap option is not safe to leave enabled once bootstrapping is complete. (They also show setting -bootstrap across all nodes, which is not correct.) It took some trial and error and reading of the module code to get automatic bootstrapping to work:

- hosts: consul_public
  become: yes
  become_user: root
  vars:
    consul_version: 0.6.4
    consul_is_server: true
    consul_datacenter: dev
    consul_node_name: "{{ ansible_default_ipv4['address'] }}"
    consul_bind_address: "{{ ansible_default_ipv4['address'] }}"
    consul_bootstrap_expect: "{{ groups['consul_private'] | length }}"
    consul_servers: "{{ groups['consul_private'] }}"
    consul_retry_join: true
  roles:
    - ansible-consul

This example demonstrates using a public IP address for deployment via SSH, but configuring the Consul cluster to use private IP addresses (ansible_default_ipv4 returns private IP addresses). It also uses a non-root account for SSH (which requires applying a fix for #146, such as PR #159, for recent Ansible versions). Finally, setting consul_node_name, consul_servers, consul_join_at_start, and consul_retry_join are all necessary for consul_bootstrap_expect to work.

Update: Removed consul_join_at_start

@jeremyjh
Copy link
Contributor

jeremyjh commented Nov 13, 2016

This is a good idea but a couple of points I would change.

First, ansible_default_ipv4 does not return "private addresses". It returns whichever IP is on the default route to 8.8.8.8.

If you want to be sure which interface is used, you need to specify it. I define a variable iface as a host variable, it would contain a value such as eth1. You can retrieve an IP for an interface from the variable ansible_eth1.ip4v.address. I use the following extractor in my playbook which will get the address from the specified interface for every host in my 'consul' group.

    consul_servers: "{{ groups['consul']|map('extract', hostvars, ['ansible_' + iface, 'ipv4', 'address'])|list }}"

Another point - using consul_join_at_start along with consul_bootstrap_expect led to problems for me because the server would crash if the other members were not available at startup. Just set consul_retry_join: true and it will join the cluster at startup, retrying in case the other members haven't started yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants