diff --git a/roles/pvc/tasks/main.yml b/roles/pvc/tasks/main.yml index a092977..509d221 100644 --- a/roles/pvc/tasks/main.yml +++ b/roles/pvc/tasks/main.yml @@ -10,6 +10,8 @@ - include: zookeeper.yml tags: pvc-zookeeper +- meta: flush_handlers + - include: libvirt.yml tags: pvc-libvirt diff --git a/roles/pvc/tasks/patroni.yml b/roles/pvc/tasks/patroni.yml index c56717b..8aa2dcd 100644 --- a/roles/pvc/tasks/patroni.yml +++ b/roles/pvc/tasks/patroni.yml @@ -10,10 +10,10 @@ update-cache: yes - name: first run check - shell: "echo 'bootstrapped' > /etc/postgresql/pvc" + shell: "echo 'bootstrapped' > /etc/patroni-install" register: newinstance args: - creates: /etc/postgresql/pvc + creates: /etc/patroni-install - name: stop and disable postgresql service: @@ -66,14 +66,6 @@ dest: /usr/lib/check_mk_agent/plugins/postgres mode: 0755 -- name: ensure patroni services are enabled and started - service: - name: "{{ item }}.service" - state: started - enabled: yes - with_items: - - patroni - - name: install initial schema files copy: src: "{{ item.src }}" @@ -85,14 +77,27 @@ - { src: "patroni/powerdns-schema.sql", dest: "/etc/postgresql/powerdns-schema.sql" } - block: + - name: ensure patroni services are enabled and started on this host so it becomes header + service: + name: "{{ item }}.service" + state: started + enabled: yes + with_items: + - patroni + - name: wait 15s for cluster to initialize pause: seconds: 15 + when: newinstance.changed + run_once: yes + +- block: - name: create user for role postgresql_user: name: "{{ pvc_dns_database_user }}" password: "{{ pvc_dns_database_password }}" + encrypted: yes state: present login_host: /run/postgresql @@ -124,4 +129,13 @@ become: yes become_user: postgres - when: newinstance.changed and ansible_local.host_id == '1' + when: newinstance.changed + run_once: yes + +- name: ensure patroni services are enabled and started + service: + name: "{{ item }}.service" + state: started + enabled: yes + with_items: + - patroni diff --git a/roles/pvc/templates/patroni/patroni.yml.j2 b/roles/pvc/templates/patroni/patroni.yml.j2 index 6ce6fca..6881cc7 100644 --- a/roles/pvc/templates/patroni/patroni.yml.j2 +++ b/roles/pvc/templates/patroni/patroni.yml.j2 @@ -1,13 +1,13 @@ scope: pvcdns -namespace: /patroni +namespace: /patroni/ name: {{ ansible_hostname }} restapi: listen: '0.0.0.0:8008' - connect_address: '{{ ansible_fqdn }}:8008' + connect_address: '{{ ansible_hostname }}.{{ pvc_cluster_domain }}:8008' zookeeper: - hosts: [ {% for host in groups[ansible_local.host_group] %}'{{ host }}.{{ ansible_domain }}:2181',{% endfor %} ] + hosts: [ {% for host in groups[hostvars[inventory_hostname].group_names[0]] %}'{{ host }}.{{ pvc_cluster_domain }}:2181',{% endfor %} ] bootstrap: dcs: @@ -25,8 +25,8 @@ bootstrap: pg_hba: - local all all peer - host replication replicator 127.0.0.1/32 trust -{% for host in groups[ansible_local.host_group] %} - - host replication replicator {{ host }}.{{ ansible_domain }} trust +{% for host in groups[hostvars[inventory_hostname].group_names[0]] %} + - host replication replicator {{ host }}.{{ pvc_cluster_domain }} trust {% endfor %} - host all all 0.0.0.0/0 md5 @@ -39,7 +39,7 @@ bootstrap: postgresql: listen: '0.0.0.0:5432' - connect_address: '{{ ansible_fqdn }}:5432' + connect_address: '{{ ansible_hostname }}.{{ pvc_cluster_domain }}:5432' log_destination: 'stderr' log_min_messages: INFO custom_conf: /etc/postgresql/postgresql.pvc.conf