Skip to content

Commit

Permalink
Consul: Add a nameserver entry poining to localhost for dnsmasq (#571)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitabaks authored Feb 3, 2024
1 parent e99e5a2 commit 139535c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
6 changes: 6 additions & 0 deletions add_pgnode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@
ansible.builtin.include_vars: "vars/{{ ansible_os_family }}.yml"
tags: always

# if 'dcs_type' is 'consul'
- name: Add a nameserver entry poining to localhost for dnsmasq
ansible.builtin.set_fact:
nameservers: "{{ ['127.0.0.1'] + (nameservers | default([])) }}"
when: dcs_type == "consul" and consul_dnsmasq_enable | bool and ('127.0.0.1' not in (nameservers | default([])))

roles:
- role: hostname
- role: resolv_conf
Expand Down
6 changes: 6 additions & 0 deletions config_pgcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@
when: firewall_enabled_at_boot | bool
tags: firewall

# if 'dcs_type' is 'consul'
- name: Add a nameserver entry poining to localhost for dnsmasq
ansible.builtin.set_fact:
nameservers: "{{ ['127.0.0.1'] + (nameservers | default([])) }}"
when: dcs_type == "consul" and consul_dnsmasq_enable | bool and ('127.0.0.1' not in (nameservers | default([])))

roles:
- role: ansible-role-firewall
vars:
Expand Down
12 changes: 10 additions & 2 deletions consul.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@
when: firewall_enabled_at_boot | bool
tags: firewall

- name: Add a nameserver entry poining to localhost for dnsmasq
ansible.builtin.set_fact:
nameservers: "{{ ['127.0.0.1'] + (nameservers | default([])) }}"
when: dcs_type == "consul" and consul_dnsmasq_enable | bool and ('127.0.0.1' not in (nameservers | default([])))

- name: Redefine the consul_dnsmasq_servers variable
ansible.builtin.set_fact:
consul_dnsmasq_servers: "{{ consul_dnsmasq_servers | reject('equalto', '127.0.0.1') | list }}"
when: dcs_type == "consul" and consul_dnsmasq_enable | bool and ('127.0.0.1' in (consul_dnsmasq_servers | default([])))

roles:
- role: ansible-role-firewall
vars:
Expand All @@ -125,8 +135,6 @@

- role: hostname
- role: resolv_conf
vars:
nameservers: [127.0.0.1] # add a nameserver entry poining to localhost for dnsmasq.
- role: etc_hosts
- role: sysctl
- role: timezone
Expand Down
6 changes: 6 additions & 0 deletions deploy_pgcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@
when: firewall_enabled_at_boot | bool
tags: firewall

# if 'dcs_type' is 'consul'
- name: Add a nameserver entry poining to localhost for dnsmasq
ansible.builtin.set_fact:
nameservers: "{{ ['127.0.0.1'] + (nameservers | default([])) }}"
when: dcs_type == "consul" and consul_dnsmasq_enable | bool and ('127.0.0.1' not in (nameservers | default([])))

roles:
- role: ansible-role-firewall
environment: "{{ proxy_env | default({}) }}"
Expand Down
7 changes: 1 addition & 6 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ proxy_env: {} # yamllint disable rule:braces
cluster_vip: "" # IP address for client access to the databases in the cluster (optional).
vip_interface: "{{ ansible_default_ipv4.interface }}" # interface name (e.g., "ens32").
# Note: VIP-based solutions such as keepalived or vip-manager may not function correctly in cloud environments like AWS.
# Recommendations for cloud environments:
# - For the "Type A" scheme: Use DNS records listing all HAProxy load balancing servers instead of relying on cluster_vip.
# - For the "Type B" scheme: Use libpq `target_session_attrs`, ensuring read/write connections go to the primary database, as an alternative to cluster_vip.

patroni_cluster_name: "postgres-cluster" # the cluster name (must be unique for each cluster)
patroni_install_version: "3.2.2" # or 'latest'
Expand Down Expand Up @@ -108,9 +105,7 @@ consul_tls_server_key: "server.key"
consul_recursors: [] # List of upstream DNS servers
consul_dnsmasq_enable: true # Enable DNS forwarding with Dnsmasq
consul_dnsmasq_cache: 0 # dnsmasq cache-size (0 - disable caching)
consul_dnsmasq_servers: # Upstream DNS servers used by dnsmasq
- "8.8.8.8"
- "9.9.9.9"
consul_dnsmasq_servers: "{{ nameservers }}" # Upstream DNS servers used by dnsmasq
consul_join: [] # List of LAN servers of an existing consul cluster, to join.
# - "10.128.64.140"
# - "10.128.64.142"
Expand Down

0 comments on commit 139535c

Please sign in to comment.