From 29f3186f165565e03b3b091523f8b682be99404a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Helleboid?= Date: Thu, 2 May 2019 17:34:44 +0200 Subject: Allow to use any ansible become method The variable can be set to 'sudo' if ansible uses sudo --- README.md | 3 +++ defaults/main.yml | 2 ++ tasks/postgres-common-postinstall.yml | 2 +- tasks/postgres-database-extensions.yml | 2 +- tasks/postgres-database.yml | 4 ++-- tasks/postgres-user.yml | 4 ++-- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 06622c8..5482bc6 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,9 @@ postgres_allowed_hosts: postgres_replication_hosts: - user: replicator range: 10.0.0.0/24 + +# Ansible related Configuration +postgres_become_method: su # Optional ``` #### Testing diff --git a/defaults/main.yml b/defaults/main.yml index 190ce5f..5876e94 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,6 +7,8 @@ postgres_clusters: [] # postgres_pgbadger_server: ~ postgres_backup_enabled: false postgres_barman_rsync_enabled: false + +postgres_become_method: su #------------------------------------------------------------# #------------ Postgresql Configuration defaults -------------# #- WARNING: defaults can change with major version upgrades -# diff --git a/tasks/postgres-common-postinstall.yml b/tasks/postgres-common-postinstall.yml index 715782c..9be3bde 100644 --- a/tasks/postgres-common-postinstall.yml +++ b/tasks/postgres-common-postinstall.yml @@ -7,7 +7,7 @@ command: ssh-keygen -b 4096 -f /var/lib/postgresql/.ssh/id_rsa -N "" -q become: yes become_user: postgres - become_method: su + become_method: "{{ postgres_become_method }}" args: creates: /var/lib/postgresql/.ssh/id_rsa diff --git a/tasks/postgres-database-extensions.yml b/tasks/postgres-database-extensions.yml index edc4e8d..58585c0 100644 --- a/tasks/postgres-database-extensions.yml +++ b/tasks/postgres-database-extensions.yml @@ -13,7 +13,7 @@ - name: "CREATE EXTENSION on database {{ postgres_dbname }}" become: true become_user: postgres - become_method: su + become_method: "{{ postgres_become_method }}" postgresql_ext: name: "{{ postgres_extension_name }}" db: "{{ postgres_dbname }}" diff --git a/tasks/postgres-database.yml b/tasks/postgres-database.yml index c3537ea..0be2dff 100644 --- a/tasks/postgres-database.yml +++ b/tasks/postgres-database.yml @@ -1,7 +1,7 @@ - name: Test if the PostgreSQL server is up become: true become_user: postgres - become_method: su + become_method: "{{ postgres_become_method }}" command: psql --port={{ postgres_port }} --command='select NOW()' register: postgres_up ignore_errors: yes @@ -11,7 +11,7 @@ - name: Create PostgreSQL database become: true become_user: postgres - become_method: su + become_method: "{{ postgres_become_method }}" postgresql_db: port: "{{ postgres_port }}" name: "{{ postgres_dbname }}" diff --git a/tasks/postgres-user.yml b/tasks/postgres-user.yml index 308dab8..fcef9fc 100644 --- a/tasks/postgres-user.yml +++ b/tasks/postgres-user.yml @@ -1,7 +1,7 @@ - name: Test if the PostgreSQL server is up become: true become_user: postgres - become_method: su + become_method: "{{ postgres_become_method }}" command: psql --port={{ postgres_port }} --command='select NOW()' register: postgres_up ignore_errors: yes @@ -11,7 +11,7 @@ - name: Create PostgreSQL user become: true become_user: postgres - become_method: su + become_method: "{{ postgres_become_method }}" postgresql_user: port: "{{ postgres_port }}" name: "{{ postgres_username }}" -- cgit v1.2.3