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

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -