diff --git a/defaults/main.yml b/defaults/main.yml index cfd14af..e9ff6c7 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,11 +4,9 @@ _consul: user: "root" group: "root" config_dir: "{{ CONSUL_CONFIG_DIR }}" - daemon_args: - - "-config-dir={{ CONSUL_CONFIG_DIR }}" - - "-bind=0.0.0.0" - - "-client=127.0.0.1" - - "-node={{ ansible_fqdn }}" + bind_addr: 0.0.0.0 + client_addr: 127.0.0.1 + node_name: "{{ ansible_fqdn }}" service_name: "consul" flags: - "-syslog" diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..8a962e3 --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,3 @@ +- name: Reload SystemD configs + ansible.builtin.systemd: + daemon_reload: true diff --git a/tasks/main.yml b/tasks/main.yml index 407b3c1..5cdad49 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -8,13 +8,15 @@ group: "root" mode: "0755" -- name: Create Consul Defaults File +- name: Create Consul env File ansible.builtin.template: - src: "etc/default/consul.j2" - dest: "/etc/default/{{ _consul.service_name }}" + src: "etc/consul.d/{{ item }}.j2" + dest: "{{ _consul.config_dir }}/{{ item }}" owner: "root" group: "root" mode: "0755" + with_items: + - "consul.env" - name: Create Consul Configuration Files ... Main ansible.builtin.template: @@ -130,3 +132,5 @@ line: "OOMScoreAdjust={{ _consul.oom_score_adj }}" insertafter: "^[Service]" when: _consul.oom_score_adj is defined + notify: + - Reload SystemD configs diff --git a/templates/etc/consul.d/consul.env.j2 b/templates/etc/consul.d/consul.env.j2 new file mode 100644 index 0000000..559f1e9 --- /dev/null +++ b/templates/etc/consul.d/consul.env.j2 @@ -0,0 +1 @@ +CONSUL_FLAGS="{{ _consul.flags|join(" ") }}" diff --git a/templates/etc/consul.d/main.json.j2 b/templates/etc/consul.d/main.json.j2 index 47cf298..a89c123 100644 --- a/templates/etc/consul.d/main.json.j2 +++ b/templates/etc/consul.d/main.json.j2 @@ -2,6 +2,24 @@ "datacenter": "{{ _consul.datacenter }}", "domain": "{{ _consul.domain }}", "data_dir": "{{ _consul.data_dir }}", +{% if _consul.bind_addr is defined %} + "bind_addr": "{{ _consul.bind_addr }}", +{% endif %} +{% if _consul.client_addr is defined %} + "client_addr": "{{ _consul.client_addr }}", +{% endif %} +{% if _consul.node_name is defined %} + "node_name": "{{ _consul.node_name }}", +{% endif %} +{% if _consul.server is defined %} + "server": {{ _consul.server | lower }}, +{% endif %} +{% if _consul.raft_protocol is defined %} + "raft_protocol": {{ _consul.raft_protocol }}, +{% endif %} +{% if _consul.ui is defined %} + "ui": {{ _consul.ui | lower }}, +{% endif %} "enable_local_script_checks": true, "dns_config": { "enable_additional_node_meta_txt": false diff --git a/templates/etc/default/consul.j2 b/templates/etc/default/consul.j2 deleted file mode 100644 index 91156f6..0000000 --- a/templates/etc/default/consul.j2 +++ /dev/null @@ -1,6 +0,0 @@ -# Specify additional flags to be added to the command line - -CONSUL_FLAGS="{{ _consul.flags|join(" ") }}" -# Nur SystemD Systeme nutzen die DAEMON_ARGS Variable. Unter Upstart wird diese nicht benötigt/benutzt -# und kann komplett ignoriert werden. Prüfe ob Werte gesetzt sind. -{% if _consul.daemon_args is defined %}DAEMON_ARGS="{{ _consul.daemon_args|join(" ") }}"{% endif %}