jumpserver/apps/accounts/automations/change_secret/database/postgresql/main.yml

42 lines
1.4 KiB
YAML
Raw Normal View History

2022-10-12 10:08:57 +00:00
- hosts: postgre
2022-10-10 12:56:13 +00:00
gather_facts: no
2022-09-19 01:52:09 +00:00
vars:
ansible_python_interpreter: /opt/py3/bin/python
2022-10-27 10:53:10 +00:00
2022-10-10 12:56:13 +00:00
tasks:
- name: Test PostgreSQL connection
2022-10-12 10:08:57 +00:00
community.postgresql.postgresql_ping:
2022-10-10 12:56:13 +00:00
login_user: "{{ jms_account.username }}"
login_password: "{{ jms_account.secret }}"
login_host: "{{ jms_asset.address }}"
login_port: "{{ jms_asset.port }}"
2023-01-31 09:57:06 +00:00
login_db: "{{ jms_asset.spec_info.db_name }}"
register: result
failed_when: not result.is_available
2022-10-10 12:56:13 +00:00
- name: Display PostgreSQL version
debug:
var: result.server_version.full
when: result is succeeded
2022-10-10 12:56:13 +00:00
- name: Change PostgreSQL password
community.postgresql.postgresql_user:
login_user: "{{ jms_account.username }}"
login_password: "{{ jms_account.secret }}"
login_host: "{{ jms_asset.address }}"
login_port: "{{ jms_asset.port }}"
2023-01-31 09:57:06 +00:00
db: "{{ jms_asset.spec_info.db_name }}"
2022-10-10 12:56:13 +00:00
name: "{{ account.username }}"
password: "{{ account.secret }}"
role_attr_flags: LOGIN
ignore_errors: true
when: result is succeeded
2022-10-10 12:56:13 +00:00
- name: Verify password
2022-10-12 10:08:57 +00:00
community.postgresql.postgresql_ping:
2022-10-10 12:56:13 +00:00
login_user: "{{ account.username }}"
login_password: "{{ account.secret }}"
login_host: "{{ jms_asset.address }}"
login_port: "{{ jms_asset.port }}"
2023-01-31 09:57:06 +00:00
db: "{{ jms_asset.spec_info.db_name }}"