postgres: store DB password with other secrets
Let’s uncomplicate our lives. Also I’m not sure if the ~/.pgpass stuff ever worked properly or even at all.
This commit is contained in:
parent
3261bc7f98
commit
8ba6959065
|
@ -65,6 +65,8 @@
|
||||||
line: "ALLOWED_HOSTS = ['{{ dns_name }}']"
|
line: "ALLOWED_HOSTS = ['{{ dns_name }}']"
|
||||||
- key: 'USER.*PostgreSQL username'
|
- key: 'USER.*PostgreSQL username'
|
||||||
line: " 'USER': '{{ user }}', # PostgreSQL username"
|
line: " 'USER': '{{ user }}', # PostgreSQL username"
|
||||||
|
- key: 'PASSWORD.*PostgreSQL password'
|
||||||
|
line: " 'PASSWORD': '{{ password.db_pass }}', # PostgreSQL password"
|
||||||
# XXX unnecessary?
|
# XXX unnecessary?
|
||||||
#- key: '(OPTIONS|PASSWORD).*PostgreSQL password'
|
#- key: '(OPTIONS|PASSWORD).*PostgreSQL password'
|
||||||
# line: " 'OPTIONS': { 'passfile': '{{ user_info.home }}/.pgpass' }, # PostgreSQL password"
|
# line: " 'OPTIONS': { 'passfile': '{{ user_info.home }}/.pgpass' }, # PostgreSQL password"
|
||||||
|
|
|
@ -10,32 +10,6 @@
|
||||||
enabled: true
|
enabled: true
|
||||||
state: started
|
state: started
|
||||||
|
|
||||||
- name: Check for existing database password
|
|
||||||
become: yes
|
|
||||||
become_user: '{{ user }}'
|
|
||||||
slurp:
|
|
||||||
path: '~/.pgpass'
|
|
||||||
register: pgpass
|
|
||||||
failed_when: false
|
|
||||||
|
|
||||||
- name: Get database password
|
|
||||||
when: '"content" in pgpass'
|
|
||||||
set_fact: db_password='{{ pgpass.content | b64decode | split(":") | last }}'
|
|
||||||
|
|
||||||
- name: Create database password
|
|
||||||
when: '"content" not in pgpass'
|
|
||||||
set_fact: db_password='{{ lookup("password", "/dev/null", chars=["ascii_letters", "digits"]) }}'
|
|
||||||
|
|
||||||
- name: Create .pgpass
|
|
||||||
become: yes
|
|
||||||
become_user: '{{ user }}'
|
|
||||||
copy:
|
|
||||||
dest: '~/.pgpass'
|
|
||||||
content: |
|
|
||||||
localhost:5432:{{ user }}:{{ user }}:{{ db_password }}
|
|
||||||
force: no
|
|
||||||
mode: 0600
|
|
||||||
|
|
||||||
- become: yes
|
- become: yes
|
||||||
become_user: postgres
|
become_user: postgres
|
||||||
block:
|
block:
|
||||||
|
@ -47,8 +21,7 @@
|
||||||
postgresql_user:
|
postgresql_user:
|
||||||
db: '{{ database | default(user) }}'
|
db: '{{ database | default(user) }}'
|
||||||
name: '{{ user }}'
|
name: '{{ user }}'
|
||||||
password: '{{ db_password }}'
|
password: '{{ password.db_pass }}'
|
||||||
no_password_changes: '{{ "content" in pgpass }}'
|
|
||||||
|
|
||||||
- name: Set schema owner
|
- name: Set schema owner
|
||||||
postgresql_owner:
|
postgresql_owner:
|
||||||
|
|
Loading…
Reference in a new issue