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

48 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:
2022-10-10 12:56:13 +00:00
ansible_python_interpreter: /usr/local/bin/python
jms_account:
username: postgre
2022-10-12 10:08:57 +00:00
secret: postgre
2022-10-10 12:56:13 +00:00
jms_asset:
address: 127.0.0.1
port: 5432
2022-10-12 10:08:57 +00:00
database: testdb
2022-09-19 01:52:09 +00:00
account:
2022-10-12 10:08:57 +00:00
username: test
2022-10-10 12:56:13 +00:00
secret: jumpserver
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 }}"
2022-10-12 10:08:57 +00:00
login_db: "{{ jms_asset.database }}"
2022-10-10 12:56:13 +00:00
register: db_info
- name: Display PostgreSQL version
debug:
var: db_info.version.full
- 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 }}"
2022-10-12 10:08:57 +00:00
db: "{{ jms_asset.database }}"
2022-10-10 12:56:13 +00:00
name: "{{ account.username }}"
password: "{{ account.secret }}"
when: db_info is succeeded
- 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 }}"
2022-10-12 10:08:57 +00:00
db: "{{ jms_asset.database }}"