# Playbook for Ansible to correct Data Dictionary entry for column
# appuser_password_repeat

- hosts: all:!peterlackegroup
  gather_facts: no

  tasks:

    - name: check if postgres is running on this server
      shell: pgrep -c postgres
      register: pgrep_output
      ignore_errors: true
      check_mode: False

    - name: end host if postgres is not running
      meta: end_host
      when: pgrep_output.stdout == "0"
      check_mode: False

    - name: check if perfactema database exists
      shell: psql -U postgres -c "\l" | grep perfactema
      register: database
      check_mode: False

    - name: end host if no perfactema database is found
      meta: end_host
      when: database.stdout | length == "0"
      check_mode: False

    - name: update datadict entry for appuser_password_repeat
      become: true
      become_method: su
      become_user: perfact
      shell: >-
        psql perfactema zope -c "update datadict set datadict_datadictint_id = 15 where datadict_colname = 'appuser_password_repeat';"

