diff --git a/tasks/configure.yml b/tasks/configure.yml index 41273787..72ff2c17 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -17,12 +17,12 @@ register: pgdata_dir_exist - name: PostgreSQL | Ensure the locale is generated | Debian - sudo: yes + become: yes locale_gen: name="{{ postgresql_locale }}" state=present when: ansible_os_family == "Debian" - name: PostgreSQL | Ensure the locale is generated | RedHat - sudo: yes + become: yes command: > localedef -c -i {{ postgresql_locale_parts[0] }} -f {{ postgresql_locale_parts[1] }} {{ postgresql_locale }} @@ -31,8 +31,8 @@ - name: PostgreSQL | Reset the cluster - drop the existing one | Debian shell: pg_dropcluster --stop {{ postgresql_version }} {{ postgresql_cluster_name }} - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{ postgresql_service_user }}" when: ansible_os_family == "Debian" and postgresql_cluster_reset and pgdata_dir_exist.changed - name: PostgreSQL | Reset the cluster - create a new one (with specified encoding and locale) | Debian @@ -40,8 +40,8 @@ pg_createcluster --start --locale {{ postgresql_locale }} -e {{ postgresql_encoding }} -d {{ postgresql_data_directory }} {{ postgresql_version }} {{ postgresql_cluster_name }} - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{ postgresql_service_user }}" when: ansible_os_family == "Debian" and postgresql_cluster_reset and pgdata_dir_exist.changed - name: PostgreSQL | Check whether the postgres data directory is initialized @@ -54,8 +54,8 @@ command: > {{ postgresql_bin_directory }}/initdb -D {{ postgresql_data_directory }} --locale={{ postgresql_locale }} --encoding={{ postgresql_encoding }} - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{ postgresql_service_user }}" when: ansible_os_family == "RedHat" and (postgresql_cluster_reset or pgdata_dir_exist.changed or @@ -89,8 +89,8 @@ register: postgresql_configuration_pt2 - name: PostgreSQL | Update configuration - pt. 3 (pgtune) - sudo: true - sudo_user: "{{ postgresql_service_user }}" + become: true + become_user: "{{ postgresql_service_user }}" shell: | set -e TMPDIR=$(mktemp -d) diff --git a/tasks/databases.yml b/tasks/databases.yml index 296eacc4..d303b50a 100644 --- a/tasks/databases.yml +++ b/tasks/databases.yml @@ -16,15 +16,15 @@ template: "template0" state: present login_user: "{{postgresql_admin_user}}" - sudo: yes - sudo_user: "{{postgresql_admin_user}}" + become: yes + become_user: "{{postgresql_admin_user}}" with_items: postgresql_databases when: postgresql_databases|length > 0 - name: PostgreSQL | Add extensions to the databases shell: "psql {{item.0.db}} --username {{postgresql_admin_user}} -c 'CREATE EXTENSION IF NOT EXISTS {{ item.1 }};'" - sudo: yes - sudo_user: "{{postgresql_admin_user}}" + become: yes + become_user: "{{postgresql_service_user}}" with_subelements: - postgresql_database_extensions - extensions @@ -32,8 +32,8 @@ changed_when: "'NOTICE' not in result.stderr" - name: PostgreSQL | Add hstore to the databases with the requirement - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{postgresql_service_user}}" shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} -c 'CREATE EXTENSION IF NOT EXISTS hstore;'" with_items: postgresql_databases register: hstore_ext_result @@ -42,8 +42,8 @@ when: item.hstore is defined and item.hstore - name: PostgreSQL | Add uuid-ossp to the database with the requirement - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{postgresql_service_user}}" shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'" with_items: postgresql_databases register: uuid_ext_result @@ -52,36 +52,36 @@ when: item.uuid_ossp is defined and item.uuid_ossp - name: PostgreSQL | Add postgis to the databases with the requirement - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{postgresql_service_user}}" shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} -c 'CREATE EXTENSION IF NOT EXISTS postgis;'&&psql {{item.name}} -c 'CREATE EXTENSION IF NOT EXISTS postgis_topology;'" with_items: postgresql_databases when: item.gis is defined and item.gis - name: PostgreSQL | add cube to the database with the requirement - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{postgresql_service_user}}" shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} -c 'create extension if not exists cube;'" with_items: postgresql_databases when: item.cube is defined and item.cube - name: PostgreSQL | Add plpgsql to the database with the requirement - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{postgresql_service_user}}" shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} -c 'CREATE EXTENSION IF NOT EXISTS plpgsql;'" with_items: postgresql_databases when: item.plpgsql is defined and item.plpgsql - name: PostgreSQL | add earthdistance to the database with the requirement - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{postgresql_service_user}}" shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} -c 'create extension if not exists earthdistance;'" with_items: postgresql_databases when: item.earthdistance is defined and item.earthdistance - name: PostgreSQL | Add citext to the database with the requirement - sudo: yes - sudo_user: "{{ postgresql_service_user }}" + become: yes + become_user: "{{postgresql_service_user}}" shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} -c 'CREATE EXTENSION IF NOT EXISTS citext;'" with_items: postgresql_databases register: citext_ext_result diff --git a/tasks/users.yml b/tasks/users.yml index 51a3bd28..46cfe6dc 100644 --- a/tasks/users.yml +++ b/tasks/users.yml @@ -13,7 +13,7 @@ port: "{{postgresql_port}}" state: present login_user: "{{postgresql_admin_user}}" - sudo: yes - sudo_user: "{{postgresql_admin_user}}" + become: yes + become_user: "{{postgresql_admin_user}}" with_items: postgresql_users when: postgresql_users|length > 0 diff --git a/tasks/users_privileges.yml b/tasks/users_privileges.yml index 6d5905fe..baad395b 100644 --- a/tasks/users_privileges.yml +++ b/tasks/users_privileges.yml @@ -10,7 +10,7 @@ login_host: "{{item.host | default(omit)}}" login_user: "{{postgresql_admin_user}}" role_attr_flags: "{{item.role_attr_flags | default(omit)}}" - sudo: yes - sudo_user: "{{postgresql_admin_user}}" + become: yes + become_user: "{{postgresql_admin_user}}" with_items: postgresql_user_privileges when: postgresql_users|length > 0 diff --git a/tests/playbook.yml b/tests/playbook.yml index a201a96f..e53db54b 100644 --- a/tests/playbook.yml +++ b/tests/playbook.yml @@ -2,7 +2,7 @@ - hosts: all remote_user: root - sudo: yes + become: yes vars_files: - ./vars.yml roles: