fix: Only update user password if the user was not created yet

This commit is contained in:
2025-10-20 21:39:44 +02:00
parent 772eb52dbe
commit 1c6d2e82b3
+25
View File
@@ -1,16 +1,41 @@
--- ---
- name: Check if postgres password exists
ansible.builtin.stat:
path: ~/.pretix_db_password
register: pretix_db_password_file
- name: Read in postgres password
ansible.builtin.command:
cmd: cat ~/.pretix_db_password
register: pretix_db_password
when: pretix_db_password_file.stat.exists
- name: Create DB user password - name: Create DB user password
ansible.builtin.command: ansible.builtin.command:
cmd: openssl rand -hex 32 cmd: openssl rand -hex 32
register: pretix_db_password register: pretix_db_password
changed_when: false changed_when: false
when: not pretix_db_password_file.stat.exists
- name: Create DB user - name: Create DB user
community.postgresql.postgresql_user: community.postgresql.postgresql_user:
login_user: "{{ ssh_user }}"
login_unix_socket: "/home/{{ ssh_user }}/tmp"
login_db: "postgres"
name: "{{ ssh_user }}_pretix" name: "{{ ssh_user }}_pretix"
password: "{{ pretix_db_password.stdout }}" password: "{{ pretix_db_password.stdout }}"
state: present state: present
environment:
PGOPTIONS: "-c password_encryption=scram-sha-256"
- name: Write out DB user password
ansible.builtin.copy:
content: "{{ pretix_db_password.stdout }}"
dest: ~/.pretix_db_password
owner: "{{ ssh_user }}"
group: "{{ ssh_user }}"
mode: "600"
- name: Create database - name: Create database
community.postgresql.postgresql_db: community.postgresql.postgresql_db:
login_user: "{{ ssh_user }}"
login_unix_socket: "/home/{{ ssh_user }}/tmp"
maintenance_db: "postgres"
name: "{{ ssh_user }}_pretix" name: "{{ ssh_user }}_pretix"
owner: "{{ ssh_user }}_pretix" owner: "{{ ssh_user }}_pretix"
encoding: UTF-8 encoding: UTF-8