2023-04-13 11:02:04 +00:00
|
|
|
- hosts: postgre
|
|
|
|
gather_facts: no
|
|
|
|
vars:
|
2023-11-13 10:09:09 +00:00
|
|
|
ansible_python_interpreter: /opt/py3/bin/python
|
2023-04-13 11:02:04 +00:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: Test PostgreSQL connection
|
|
|
|
community.postgresql.postgresql_ping:
|
|
|
|
login_user: "{{ jms_account.username }}"
|
|
|
|
login_password: "{{ jms_account.secret }}"
|
|
|
|
login_host: "{{ jms_asset.address }}"
|
|
|
|
login_port: "{{ jms_asset.port }}"
|
|
|
|
login_db: "{{ jms_asset.spec_info.db_name }}"
|
|
|
|
register: result
|
|
|
|
failed_when: not result.is_available
|
|
|
|
|
|
|
|
- name: Display PostgreSQL version
|
|
|
|
debug:
|
|
|
|
var: result.server_version.full
|
|
|
|
when: result is succeeded
|
|
|
|
|
|
|
|
- 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 }}"
|
|
|
|
db: "{{ jms_asset.spec_info.db_name }}"
|
|
|
|
name: "{{ account.username }}"
|
|
|
|
password: "{{ account.secret }}"
|
|
|
|
role_attr_flags: LOGIN
|
2023-06-09 08:52:54 +00:00
|
|
|
ignore_errors: true
|
2023-04-13 11:02:04 +00:00
|
|
|
when: result is succeeded
|
2023-09-20 06:29:53 +00:00
|
|
|
register: change_info
|
2023-04-13 11:02:04 +00:00
|
|
|
|
|
|
|
- name: Verify password
|
|
|
|
community.postgresql.postgresql_ping:
|
|
|
|
login_user: "{{ account.username }}"
|
|
|
|
login_password: "{{ account.secret }}"
|
|
|
|
login_host: "{{ jms_asset.address }}"
|
|
|
|
login_port: "{{ jms_asset.port }}"
|
|
|
|
db: "{{ jms_asset.spec_info.db_name }}"
|
|
|
|
when:
|
|
|
|
- result is succeeded
|
|
|
|
- change_info is succeeded
|
2023-09-20 06:29:53 +00:00
|
|
|
register: result
|
|
|
|
failed_when: not result.is_available
|