diff --git a/defaults/main.yaml b/defaults/main.yaml index b06e678..8af440d 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -11,7 +11,7 @@ consul_agent_group: "consul_agent" consul_config: {} consul_default_config: - bind_addr: "{{ ansible_default_ipv4.address }}" + bind_addr: "{{ hostvars[inventory_hostname].ansible_host | default(ansible_default_ipv4.address) }}" server: "{{ true if inventory_hostname in groups[consul_server_group] else false }}" ui_config: enabled: "{{ true if inventory_hostname in groups[consul_server_group] else false }}" @@ -32,6 +32,9 @@ consul_ssl: true consul_ssl_path: "/etc/consul.d/ssl" consul_self_signed_cert: false consul_self_signed_cert_name: "consul-tls" +consul_cacert_multiple_default_gw_workaround: false +consul_cacert_force_append_ips: [] +consul_cacert_force_append_names: [] consul_server_ssl_config: {} consul_server_ssl_default_config: ports: diff --git a/tasks/cacert.yaml b/tasks/cacert.yaml index 4c9e808..9472045 100644 --- a/tasks/cacert.yaml +++ b/tasks/cacert.yaml @@ -75,12 +75,19 @@ - name: Generate consul server subject_alt_ips from default ipv4 address set_fact: consul_server_subject_alt_ips: "{{ groups[consul_server_group] | default([]) | map('extract', hostvars, ['ansible_default_ipv4', 'address']) | map('regex_replace', '^', 'IP:') | list }}" - when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] is defined + when: + - hostvars[inventory_hostname]['ansible_default_ipv4']['address'] is defined + - not consul_cacert_multiple_default_gw_workaround - name: Generate consul server subject_alt_names set_fact: consul_server_subject_alt_names: "{{ groups[consul_server_group] | default([]) | map('extract', hostvars, ['inventory_hostname']) | map('regex_replace', '^', 'DNS:') | list }}" + - name: Generate consul server subject_alt_ips from ansible_all_ipv4_addresses + set_fact: + consul_server_subject_alt_ips_all_ipv4: "{{ groups[consul_server_group] | default([]) | map('extract', hostvars, ['ansible_all_ipv4_addresses']) | flatten | map('regex_replace', '^', 'IP:') | list }}" + when: hostvars[inventory_hostname]['ansible_all_ipv4_addresses'] is defined + - name: Generate consul agent subject_alt_ips from ansible_host set_fact: consul_agent_subject_alt_ips_from_ansible_host: "{{ groups[consul_agent_group] | default([]) | map('extract', hostvars, ['ansible_host']) | map('regex_replace', '^', 'IP:') | list }}" @@ -89,7 +96,24 @@ - name: Generate consul agent subject_alt_ips from default ipv4 address set_fact: consul_agent_subject_alt_ips: "{{ groups[consul_agent_group] | default([]) | map('extract', hostvars, ['ansible_default_ipv4', 'address']) | map('regex_replace', '^', 'IP:') | list }}" - when: hostvars[inventory_hostname]['ansible_default_ipv4']['address'] is defined + when: + - hostvars[inventory_hostname]['ansible_default_ipv4']['address'] is defined + - not consul_cacert_multiple_default_gw_workaround + + - name: Generate consul agent subject_alt_ips from ansible_all_ipv4_addresses + set_fact: + consul_agent_subject_alt_ips_all_ipv4: "{{ groups[consul_agent_group] | default([]) | map('extract', hostvars, ['ansible_all_ipv4_addresses']) | flatten | map('regex_replace', '^', 'IP:') | list }}" + when: hostvars[inventory_hostname]['ansible_all_ipv4_addresses'] is defined + + - name: Generate consul agent subject_alt_ips from cacert_force_append_ips + set_fact: + consul_agent_subject_alt_ips_force_append: "{{ cacert_force_append_ips | map('regex_replace', '^', 'IP:') | list }}" + when: cacert_force_append_ips is defined + + - name: Generate consul agent subject_alt_names from cacert_force_append_names + set_fact: + consul_agent_subject_alt_names_force_append: "{{ cacert_force_append_names | map('regex_replace', '^', 'DNS:') | list }}" + when: cacert_force_append_names is defined - name: Generate consul agent subject_alt_names set_fact: @@ -100,7 +124,7 @@ path: "{{ consul_ssl_path }}/{{ consul_self_signed_cert_name }}.csr" privatekey_path: "{{ consul_ssl_path }}/{{ consul_self_signed_cert_name }}.key" common_name: "{{ consul_self_signed_cert_name }}" - subject_alt_name: "{{ consul_server_subject_alt_ips | default([]) + consul_server_subject_alt_names | default([]) + consul_agent_subject_alt_ips | default([]) + consul_agent_subject_alt_names | default([]) + consul_server_subject_alt_ips_from_ansible_host | default([]) + consul_agent_subject_alt_ips_from_ansible_host | default([]) }}" + subject_alt_name: "{{ consul_server_subject_alt_ips | default([]) + consul_server_subject_alt_names | default([]) + consul_agent_subject_alt_ips | default([]) + consul_agent_subject_alt_names | default([]) + consul_server_subject_alt_ips_from_ansible_host | default([]) + consul_server_subject_alt_ips_all_ipv4 | default([]) + consul_agent_subject_alt_ips_from_ansible_host | default([]) + consul_agent_subject_alt_ips_all_ipv4 | default([]) + consul_agent_subject_alt_ips_force_append | default([]) + consul_agent_subject_alt_names_force_append | default([])}}" owner: consul group: consul register: consul_csr