postgresql - How can u make psql process idempotent in ansible? -
i have process runs psql
process in ansible
- name: run psql pull in initial config data become_method: sudo become: yes become_user: postgres shell: psql -u postgres -w eclaim < /opt/eclaim_revamp/sql_scripts/{{ item }}.sql with_items: - initial_config - initial_sql_script - tmp_hrms
this task runs time. how make idempotent ?
i guess way wrap sql-script shell scripts , make checks.
example (i know there postgresql_user
module, example):
#!/bin/bash if [[ $(psql postgres -tac "select 'found' pg_roles rolname='{{ user }}'" | grep found) ]]; echo "user exists" else psql -c "create user {{ user }} login encrypted password '{{ password }}';" > /dev/null echo "user created" fi
and in playbook:
- name: run psql shell: createuser.sh register: result changed_when: "'user created' in result.stdout"
Comments
Post a Comment