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

44 lines
1.4 KiB
YAML
Raw Normal View History

- hosts: mongodb
gather_facts: no
vars:
ansible_python_interpreter: /usr/local/bin/python
tasks:
- name: Test MongoDB connection
mongodb_ping:
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_database: "{{ jms_asset.spec_info.db_name }}"
register: db_info
- name: Display MongoDB version
debug:
var: db_info.server_version
when: db_info is succeeded
- name: Change MongoDB password
mongodb_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
login_database: "{{ jms_asset.spec_info.db_name }}"
db: "{{ jms_asset.spec_info.db_name }}"
name: "{{ account.username }}"
password: "{{ account.secret }}"
when: db_info is succeeded
register: change_info
- name: Verify password
mongodb_ping:
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
login_database: "{{ jms_asset.spec_info.db_name }}"
when:
2023-01-31 09:57:06 +00:00
- db_info is succeeded
- change_info is succeeded