Wrap up basic consul server
This commit is contained in:
parent
aabc5936b7
commit
8988e78e39
8 changed files with 152 additions and 13 deletions
3
ansible/host_vars/fatman.minhas.io/main.yml
Normal file
3
ansible/host_vars/fatman.minhas.io/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
consul_dc: columbia
|
||||||
|
...
|
3
ansible/host_vars/ivyking.minhas.io/main.yml
Normal file
3
ansible/host_vars/ivyking.minhas.io/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
consul_dc: columbia
|
||||||
|
...
|
3
ansible/host_vars/sedan.minhas.io/main.yml
Normal file
3
ansible/host_vars/sedan.minhas.io/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
---
|
||||||
|
consul_dc: columbia
|
||||||
|
...
|
15
ansible/roles/consul_server/files/consul.service
Normal file
15
ansible/roles/consul_server/files/consul.service
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Consul Service Discovery Agent
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
Restart=on-failure
|
||||||
|
User=consul
|
||||||
|
Group=consul
|
||||||
|
RestartSec=3
|
||||||
|
StateDirectory=consul
|
||||||
|
ExecStart=/usr/local/bin/consul agent -config-dir /etc/consul.d/
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
14
ansible/roles/consul_server/handlers/main.yml
Normal file
14
ansible/roles/consul_server/handlers/main.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
- name: daemon_reload
|
||||||
|
systemd:
|
||||||
|
daemon_reload: True
|
||||||
|
|
||||||
|
- name: restart_consul_debian
|
||||||
|
systemd:
|
||||||
|
name: consul
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
- name: restart_consul_fbsd
|
||||||
|
service:
|
||||||
|
name: consul
|
||||||
|
state: restarted
|
|
@ -1,4 +1,33 @@
|
||||||
---
|
---
|
||||||
|
- name: ensure consul group
|
||||||
|
group:
|
||||||
|
name: consul
|
||||||
|
state: present
|
||||||
|
system: True
|
||||||
|
|
||||||
|
- name: ensure consul user
|
||||||
|
user:
|
||||||
|
name: consul
|
||||||
|
state: present
|
||||||
|
group: consul
|
||||||
|
system: True
|
||||||
|
|
||||||
|
- name: ensure consul config dir
|
||||||
|
file:
|
||||||
|
path: /etc/consul.d/
|
||||||
|
state: directory
|
||||||
|
owner: consul
|
||||||
|
group: consul
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: ensure consul data dir
|
||||||
|
file:
|
||||||
|
path: /opt/consul
|
||||||
|
state: directory
|
||||||
|
owner: consul
|
||||||
|
group: consul
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
- name: check consul version
|
- name: check consul version
|
||||||
shell:
|
shell:
|
||||||
cmd: "consul --version | head -1 | cut -d'v' -f2"
|
cmd: "consul --version | head -1 | cut -d'v' -f2"
|
||||||
|
@ -6,6 +35,7 @@
|
||||||
executable: /bin/bash
|
executable: /bin/bash
|
||||||
changed_when: False
|
changed_when: False
|
||||||
register: installed_consul_version
|
register: installed_consul_version
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
- name: get consul
|
- name: get consul
|
||||||
unarchive:
|
unarchive:
|
||||||
|
@ -14,5 +44,29 @@
|
||||||
mode: 0755
|
mode: 0755
|
||||||
owner: root
|
owner: root
|
||||||
group: root
|
group: root
|
||||||
remote_src: yes
|
remote_src: True
|
||||||
when: installed_consul_version.stdout != consul_version
|
when: installed_consul_version.stdout != consul_version
|
||||||
|
|
||||||
|
- name: copy consul unit file
|
||||||
|
copy:
|
||||||
|
src: files/consul.service
|
||||||
|
dest: /etc/systemd/system/consul.service
|
||||||
|
mode: 0755
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
notify: daemon_reload
|
||||||
|
|
||||||
|
- name: template consul config
|
||||||
|
template:
|
||||||
|
src: templates/consul.hcl.j2
|
||||||
|
dest: /etc/consul.d/consul.hcl
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: 0755
|
||||||
|
notify: restart_consul_debian
|
||||||
|
|
||||||
|
- name: ensure consul is started and enabled
|
||||||
|
systemd:
|
||||||
|
name: consul
|
||||||
|
state: started
|
||||||
|
enabled: True
|
||||||
|
|
|
@ -1,4 +1,33 @@
|
||||||
---
|
---
|
||||||
|
- name: ensure consul group
|
||||||
|
group:
|
||||||
|
name: consul
|
||||||
|
state: present
|
||||||
|
system: True
|
||||||
|
|
||||||
|
- name: ensure consul user
|
||||||
|
user:
|
||||||
|
name: consul
|
||||||
|
state: present
|
||||||
|
group: consul
|
||||||
|
system: True
|
||||||
|
|
||||||
|
- name: ensure consul config dir
|
||||||
|
file:
|
||||||
|
path: /usr/local/etc/consul.d/
|
||||||
|
state: directory
|
||||||
|
owner: consul
|
||||||
|
group: consul
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: ensure consul data dir
|
||||||
|
file:
|
||||||
|
path: /opt/consul
|
||||||
|
state: directory
|
||||||
|
owner: consul
|
||||||
|
group: consul
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
- name: check consul version
|
- name: check consul version
|
||||||
shell:
|
shell:
|
||||||
cmd: "consul --version | head -1 | cut -d'v' -f2"
|
cmd: "consul --version | head -1 | cut -d'v' -f2"
|
||||||
|
@ -7,20 +36,24 @@
|
||||||
changed_when: False
|
changed_when: False
|
||||||
failed_when: False
|
failed_when: False
|
||||||
register: installed_consul_version
|
register: installed_consul_version
|
||||||
|
check_mode: false
|
||||||
|
|
||||||
- name: get consul
|
- name: get consul
|
||||||
get_url:
|
pkgng:
|
||||||
url: "https://releases.hashicorp.com/consul/{{ consul_version }}/consul_{{ consul_version }}_freebsd_amd64.zip"
|
name: consul-{{ consul_version }}
|
||||||
dest: /tmp/consul.zip
|
state: present
|
||||||
when: ("No such file" not in installed_consul_version.msg) or (installed_consul_version.msg != consul_version)
|
|
||||||
register: get_consul
|
|
||||||
|
|
||||||
- name: get consul
|
- name: template consul config
|
||||||
unarchive:
|
template:
|
||||||
src: /tmp/consul.zip
|
src: templates/consul.hcl.j2
|
||||||
dest: /usr/local/bin/
|
dest: /usr/local/etc/consul.d/consul.hcl
|
||||||
remote_src: True
|
|
||||||
mode: 0755
|
|
||||||
owner: root
|
owner: root
|
||||||
group: staff
|
group: staff
|
||||||
when: get_consul.changed
|
mode: 0755
|
||||||
|
notify: restart_consul_fbsd
|
||||||
|
|
||||||
|
- name: enable and start consul
|
||||||
|
service:
|
||||||
|
name: consul
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
|
14
ansible/roles/consul_server/templates/consul.hcl.j2
Normal file
14
ansible/roles/consul_server/templates/consul.hcl.j2
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
datacenter = "{{ consul_dc }}"
|
||||||
|
bind_addr = "{{ ansible_default_ipv4.address }}"
|
||||||
|
start_join = ["{{ groups['consul_server'] | map('extract', hostvars, ['ansible_default_ipv4', 'address']) | join('","') }}"]
|
||||||
|
data_dir = "/opt/consul"
|
||||||
|
log_level = "INFO"
|
||||||
|
server = true
|
||||||
|
bootstrap_expect = 3
|
||||||
|
ui = true
|
||||||
|
addresses {
|
||||||
|
http = "0.0.0.0"
|
||||||
|
}
|
||||||
|
performance {
|
||||||
|
raft_multiplier = 1
|
||||||
|
}
|
Loading…
Reference in a new issue