---
- name: Consul installed
  community.general.pkgng:
    name: "consul"
    state: latest
  tags:
    - dc1
    - dc2

- name: Consul enabled
  shell: sysrc consul_enable="YES"
  tags:
    - dc1
    - dc2
  notify: Consul restarted

- name: Consul syslog output
  shell: sysrc consul_syslog_output_enable="YES"
  tags:
    - dc1
    - dc2
  notify: Consul restarted

- name: Consul dc1 nodes configured
  shell: sysrc consul_args="-server -client 0.0.0.0 -ui -bootstrap-expect=3 -datacenter dc1 -retry-join-wan nomad11.local -retry-join nomad00.local -retry-join nomad01.local -retry-join nomad02.local -retry-join nomad03.local"
  tags:
    - dc1
  notify: Consul restarted

- name: Consul dc2 nodes configured
  shell: sysrc consul_args="-server -client 0.0.0.0 -ui -bootstrap-expect=3 -datacenter dc2 -retry-join-wan nomad01.local -retry-join nomad10.local -retry-join nomad11.local -retry-join nomad12.local -retry-join nomad13.local"
  tags:
    - dc2
  notify: Consul restarted

- name: Consul dc1 agent configured
  shell: sysrc consul_args="-datacenter dc1 -retry-join consul.service.dc1.consul"
  tags:
    - dc1-agents
  notify: Consul restarted

- name: Consul dc2 agent configured
  shell: sysrc consul_args="-datacenter dc2 -retry-join consul.service.dc2.consul"
  tags:
    - dc1-agents
  notify: Consul restarted

- name: Consul started
  service: name=consul state=started
  tags:
    - dc1
    - dc2
