ansible postgres

ansibleでpostgresqlインストール
https://qiita.com/kitaro_tn/items/04aa7279c17be8b9b0ed

To achieve your desired functionality add this to your sudoers file

%group1 ALL=(user2) NOPASSWD: /full/path/to/script2

This will allow group1 to run script2 as user2 without entering a password.

https://unix.stackexchange.com/questions/399586/sudo-u-in-script-still-prompts-for-invoking-user-password/399588

become_user: postgres には

`ansible実行ユーザ` ALL=(postgres) NOPASSWD: ALL

が必要、例

debian ALL=(vdc) NOPASSWD: ALL

su -u postgres でパスワードが必要だと sudo: a password is required のエラーになる。

http://docs.ansible.com/ansible/latest/become.html

postgresql_db_module

http://docs.ansible.com/ansible/latest/postgresql_db_module.html

https://stackoverflow.com/questions/29337686/pgsql-how-to-import-database-dump-only-when-database-completely-empty

DB作成時のみ、restoreをしたい場合

- postgresql_db: 
    name: "{{ dbname }}"
    encoding: "UTF-8"
  register: createdb
  become_user: postgres

- copy: src=restore.sql dest=/tmp/restore.sql

- postgresql_db: 
    name: "{{ dbname }}"
    state: restore
    target: /tmp/restore.sql
  become_user: postgres
  when: createdb.changed