Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
introduce postgresql_login_port variable to handle docker containers …
…with exported postgres port not on 5432
  • Loading branch information
lhoss authored and Laurent Hoss committed Sep 18, 2017
commit 83a2c4b41e86c6707fff6cc189b02539a43c9d15
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ postgresql_admin_user: "postgres"
postgresql_admin_pwd: ""
postgresql_default_auth_method: "trust"
postgresql_login_host: "localhost"
postgresql_login_port: 5432

# The user/group that will run postgresql process or service
postgresql_service_user: "{{ postgresql_admin_user }}"
Expand Down
18 changes: 9 additions & 9 deletions tasks/databases-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
encoding: "{{ item.encoding | default(postgresql_encoding) }}"
lc_collate: "{{ item.lc_collate | default(postgresql_locale) }}"
lc_ctype: "{{ item.lc_ctype | default(postgresql_ctype) }}"
port: "{{postgresql_port}}"
port: "{{ (postgresql_docker_mode) | ternary(postgresql_login_port, postgresql_port) }}"
template: "template0"
state: present
login_user: "{{postgresql_admin_user}}"
Expand All @@ -19,7 +19,7 @@
when: postgresql_databases|length > 0

- name: PostgreSQL | Add extensions to the databases
shell: "psql {{item.0.db}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'CREATE EXTENSION IF NOT EXISTS {{ item.1 }};'"
shell: "psql {{item.0.db}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} -c 'CREATE EXTENSION IF NOT EXISTS {{ item.1 }};'"
become: yes
become_user: "{{ (postgresql_docker_mode) | ternary('root', postgresql_service_user) }}"
with_subelements:
Expand All @@ -32,7 +32,7 @@
- name: PostgreSQL | Add hstore to the databases with the requirement
become: yes
become_user: "{{ (postgresql_docker_mode) | ternary('root', postgresql_service_user) }}"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} -c 'CREATE EXTENSION IF NOT EXISTS hstore;'"
with_items: "{{postgresql_databases}}"
register: hstore_ext_result
failed_when: hstore_ext_result.rc != 0 and ("already exists, skipping" not in hstore_ext_result.stderr)
Expand All @@ -43,7 +43,7 @@
- name: PostgreSQL | Add uuid-ossp to the database with the requirement
become: yes
become_user: "{{ (postgresql_docker_mode) | ternary('root', postgresql_service_user) }}"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} -c 'CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";'"
with_items: "{{postgresql_databases}}"
register: uuid_ext_result
failed_when: uuid_ext_result.rc != 0 and ("already exists, skipping" not in uuid_ext_result.stderr)
Expand All @@ -54,39 +54,39 @@
- name: PostgreSQL | Add postgis to the databases with the requirement
become: yes
become_user: "{{ (postgresql_docker_mode) | ternary('root', postgresql_service_user) }}"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'CREATE EXTENSION IF NOT EXISTS postgis;'&&psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'CREATE EXTENSION IF NOT EXISTS postgis_topology;'"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} -c 'CREATE EXTENSION IF NOT EXISTS postgis;'&&psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} -c 'CREATE EXTENSION IF NOT EXISTS postgis_topology;'"
with_items: "{{postgresql_databases}}"
when: item.gis is defined and item.gis
environment: "{{ postgres_env_switch }}"

- name: PostgreSQL | add cube to the database with the requirement
become: yes
become_user: "{{ (postgresql_docker_mode) | ternary('root', postgresql_service_user) }}"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'create extension if not exists cube;'"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} {{ postgres_login_host_switch }} -c 'create extension if not exists cube;'"
with_items: "{{postgresql_databases}}"
when: item.cube is defined and item.cube
environment: "{{ postgres_env_switch }}"

- name: PostgreSQL | Add plpgsql to the database with the requirement
become: yes
become_user: "{{ (postgresql_docker_mode) | ternary('root', postgresql_service_user) }}"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'CREATE EXTENSION IF NOT EXISTS plpgsql;'"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} {{ postgres_login_host_switch }} -c 'CREATE EXTENSION IF NOT EXISTS plpgsql;'"
with_items: "{{postgresql_databases}}"
when: item.plpgsql is defined and item.plpgsql
environment: "{{ postgres_env_switch }}"

- name: PostgreSQL | add earthdistance to the database with the requirement
become: yes
become_user: "{{ (postgresql_docker_mode) | ternary('root', postgresql_service_user) }}"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'create extension if not exists earthdistance;'"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{ postgresql_admin_user }} {{ postgres_login_host_switch }} -c 'create extension if not exists earthdistance;'"
with_items: "{{postgresql_databases}}"
when: item.earthdistance is defined and item.earthdistance
environment: "{{ postgres_env_switch }}"

- name: PostgreSQL | Add citext to the database with the requirement
become: yes
become_user: "{{ (postgresql_docker_mode) | ternary('root', postgresql_service_user) }}"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} --port {{postgresql_port}} -c 'CREATE EXTENSION IF NOT EXISTS citext;'"
shell: "{{ postgresql_bin_directory}}/psql {{item.name}} --username {{postgresql_admin_user}} {{ postgres_login_host_switch }} -c 'CREATE EXTENSION IF NOT EXISTS citext;'"
with_items: "{{postgresql_databases}}"
register: citext_ext_result
failed_when: citext_ext_result.rc != 0 and ("already exists, skipping" not in citext_ext_result.stderr)
Expand Down
2 changes: 1 addition & 1 deletion tasks/databases-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Prepare facts for the docker configuration
- set_fact:
postgres_login_host_switch: "--host {{postgresql_login_host}} --port {{postgresql_port}}"
postgres_login_host_switch: "--host {{postgresql_login_host}} --port {{postgresql_login_port}}"
postgres_env_switch:
PGPASSWORD: "{{postgresql_admin_pwd}}"

Expand Down
2 changes: 1 addition & 1 deletion tasks/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Prepare facts for the non-docker configuration
- set_fact:
postgres_login_host_switch: ""
postgres_login_host_switch: "--port {{postgresql_port}}"
postgres_env_switch: {}

- include: databases-common.yml
2 changes: 1 addition & 1 deletion tasks/users-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
name: "{{item.name}}"
password: "{{ item.pass | default(omit) }}"
encrypted: "{{ item.encrypted | default(omit) }}"
port: "{{postgresql_port}}"
port: "{{postgresql_login_port}}"
state: present
login_user: "{{postgresql_admin_user}}"
login_password: "{{postgresql_admin_pwd}}"
Expand Down
2 changes: 1 addition & 1 deletion tasks/users_privileges-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
postgresql_user:
name: "{{item.name}}"
db: "{{item.db | default(omit)}}"
port: "{{postgresql_port}}"
port: "{{postgresql_login_port}}"
priv: "{{item.priv | default(omit)}}"
state: present
role_attr_flags: "{{item.role_attr_flags | default(omit)}}"
Expand Down