consul reparado

This commit is contained in:
serxoz 2023-10-06 12:05:33 +02:00
parent fc16137698
commit cbacb2bffb
7 changed files with 74 additions and 17 deletions

View File

@ -1,2 +1,3 @@
[defaults] [defaults]
inventory = proxmox-inv inventory = proxmox-inv
host_key_checking = False

9
full.yml Normal file
View File

@ -0,0 +1,9 @@
- name: Instala Docker, Consul e Nomad
hosts: all
any_errors_fatal: true
become: true
become_user: root
roles:
- docker
- consul
- nomad

View File

@ -5,13 +5,17 @@ ansible_ssh_private_key_file=~/.ssh/alpine-cloud
[admin] [admin]
192.168.1.111 vm_name=hashi-1 vm_ip=192.168.1.111 192.168.1.111 vm_name=hashi-1 vm_ip=192.168.1.111
192.168.1.112 vm_name=hashi-2 vm_ip=192.168.1.112
192.168.1.113 vm_name=hashi-3 vm_ip=192.168.1.113
[client] [client]
192.168.1.112 vm_name=hashi-2 vm_ip=192.168.1.112 192.168.1.114 vm_name=hashi-4 vm_ip=192.168.1.114
[consul_node] [consul_node]
192.168.1.111 consul_iface=eth0 consul_node_role=server vm_name=hashi-1 vm_ip=192.168.1.111 192.168.1.111 consul_iface=eth0 consul_node_role=server vm_name=hashi-1 vm_ip=192.168.1.111
192.168.1.112 consul_iface=eth0 consul_node_role=client vm_name=hashi-2 vm_ip=192.168.1.112 192.168.1.112 consul_iface=eth0 consul_node_role=server vm_name=hashi-2 vm_ip=192.168.1.112
192.168.1.113 consul_iface=eth0 consul_node_role=server vm_name=hashi-3 vm_ip=192.168.1.113
192.168.1.114 consul_iface=eth0 consul_node_role=client vm_name=hashi-4 vm_ip=192.168.1.114
[consul_node:vars] [consul_node:vars]
consul_dc_name=tr4ck consul_dc_name=tr4ck
@ -19,3 +23,5 @@ consul_dc_name=tr4ck
[nomad_node] [nomad_node]
192.168.1.111 vm_name=hashi-1 vm_ip=192.168.1.111 192.168.1.111 vm_name=hashi-1 vm_ip=192.168.1.111
192.168.1.112 vm_name=hashi-2 vm_ip=192.168.1.112 192.168.1.112 vm_name=hashi-2 vm_ip=192.168.1.112
192.168.1.113 vm_name=hashi-3 vm_ip=192.168.1.113
192.168.1.114 vm_name=hashi-4 vm_ip=192.168.1.114

View File

@ -1,4 +1,9 @@
--- ---
- name: clean consul alpine distribution config
file:
state: absent
path: /etc/consul/server.json
- name: get the encrypt_key - name: get the encrypt_key
ansible.builtin.command: ansible.builtin.command:
cmd: cat /etc/consul/gossip.key cmd: cat /etc/consul/gossip.key

View File

@ -3,12 +3,6 @@
"node_name": "{{ vm_name }}", "node_name": "{{ vm_name }}",
"data_dir": "/opt/consul", "data_dir": "/opt/consul",
"encrypt": "{{ gossip.stdout }}", "encrypt": "{{ gossip.stdout }}",
"ca_file": "/etc/consul/consul-agent-ca.pem",
"cert_file": "/etc/consul/{{ consul_dc_name }}-server-consul-0.pem",
"key_file": "/etc/consul/{{ consul_dc_name }}-server-consul-0-key.pem",
"verify_incoming": false,
"verify_outgoing": true,
"verify_server_hostname": false,
"bind_addr": "{{ vm_ip }}", "bind_addr": "{{ vm_ip }}",
"addresses": { "addresses": {
"https": "{{ vm_ip }}", "https": "{{ vm_ip }}",
@ -17,15 +11,16 @@
"grpc": "{{ vm_ip }}" "grpc": "{{ vm_ip }}"
}, },
"ports": { "ports": {
"grpc_tls": 8502 "grpc": 8502
}, },
{% if 'server' in consul_node_role %} {% if 'server' in consul_node_role %}
"server": true, "server": true,
{% if consul_bootstrap_node is defined %} "bootstrap_expect":3,
"bootstrap": true, {% else %}
"bootstrap_expect":0,
{% endif %} {% endif %}
{% endif %}
"retry_join": [{% for host in groups['consul_node'] %}"{{ hostvars[host]['vm_ip'] }}"{% if not loop.last %},{% endif %}{% endfor %}], "retry_join": [{% for host in groups['admin'] %}"{{ hostvars[host]['vm_ip'] }}"{% if not loop.last %},{% endif %}{% endfor %}],
"ui_config": { "ui_config": {
"enabled": true "enabled": true
}, },

View File

@ -0,0 +1,35 @@
{
"datacenter": "{{ consul_dc_name }}",
"node_name": "{{ vm_name }}",
"data_dir": "/opt/consul",
"encrypt": "{{ gossip.stdout }}",
"ca_file": "/etc/consul/consul-agent-ca.pem",
"cert_file": "/etc/consul/{{ consul_dc_name }}-server-consul-0.pem",
"key_file": "/etc/consul/{{ consul_dc_name }}-server-consul-0-key.pem",
"verify_incoming": false,
"verify_outgoing": true,
"verify_server_hostname": false,
"bind_addr": "{{ vm_ip }}",
"addresses": {
"https": "{{ vm_ip }}",
"http": "{{ vm_ip }}",
"dns": "{{ vm_ip }}",
"grpc": "{{ vm_ip }}"
},
"ports": {
"grpc_tls": 8502
},
{% if 'server' in consul_node_role %}
"server": true,
{% if consul_bootstrap_node is defined %}
"bootstrap": true,
{% endif %}
{% endif %}
"retry_join": [{% for host in groups['consul_node'] %}"{{ hostvars[host]['vm_ip'] }}"{% if not loop.last %},{% endif %}{% endfor %}],
"ui_config": {
"enabled": true
},
"connect": {
"enabled": true
}
}

View File

@ -1,15 +1,21 @@
datacenter = "{{ nomad_datacenter }}" datacenter = "{{ nomad_datacenter }}"
data_dir = "{{ nomad_data_dir }}"
bind_addr = "0.0.0.0"
name = "{{ vm_name }}" name = "{{ vm_name }}"
data_dir = "{{ nomad_data_dir }}"
bind_addr = "0.0.0.0"
advertise {
http = "{{ vm_ip }}"
rpc = "{{ vm_ip }}"
serf = "{{ vm_ip }}"
}
{% if 'admin' in group_names %} {% if 'admin' in group_names %}
server { server {
enabled = true enabled = true
bootstrap_expect = 1 bootstrap_expect = 3
# uncoment retry_join if bootstrap_expect > 1 # uncoment retry_join if bootstrap_expect > 1
# retry_join = [{% for host in groups['admin'] %}"{{ hostvars[host]['vm_ip'] }}"{% if not loop.last %},{% endif %}{% endfor %}] retry_join = [{% for host in groups['admin'] %}"{{ hostvars[host]['vm_ip'] }}"{% if not loop.last %},{% endif %}{% endfor %}]
} }
{% endif %} {% endif %}