2020-05-05 14:04:33 +02:00
---
2020-03-17 09:59:17 +01:00
- name : postgresql_ext - install postgis on Linux
2020-03-09 10:11:07 +01:00
package : name=postgis state=present
when : ansible_os_family != "Windows"
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - create schema schema1
become_user : '{{ pg_user }}'
become : true
postgresql_schema :
database : postgres
name : schema1
state : present
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - drop extension if exists
become_user : '{{ pg_user }}'
become : true
postgresql_query :
db : postgres
query : DROP EXTENSION IF EXISTS postgis
ignore_errors : true
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - create extension postgis in check_mode
become_user : '{{ pg_user }}'
become : true
postgresql_ext :
login_db : postgres
login_port : 5432
name : postgis
check_mode : true
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result is changed
- result.queries == []
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - check that extension doesn't exist after the previous step
become_user : '{{ pg_user }}'
become : true
postgresql_query :
db : postgres
query : SELECT extname FROM pg_extension WHERE extname='postgis'
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result.rowcount == 0
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - create extension postgis
become_user : '{{ pg_user }}'
become : true
postgresql_ext :
login_db : postgres
login_port : 5432
name : postgis
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result is changed
- result.queries == ['CREATE EXTENSION "postgis"']
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - check that extension exists after the previous step
become_user : '{{ pg_user }}'
become : true
postgresql_query :
db : postgres
query : SELECT extname FROM pg_extension WHERE extname='postgis'
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result.rowcount == 1
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - drop extension postgis
become_user : '{{ pg_user }}'
become : true
postgresql_ext :
db : postgres
name : postgis
state : absent
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result is changed
- result.queries == ['DROP EXTENSION "postgis"']
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - check that extension doesn't exist after the previous step
become_user : '{{ pg_user }}'
become : true
postgresql_query :
db : postgres
query : SELECT extname FROM pg_extension WHERE extname='postgis'
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result.rowcount == 0
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - create extension postgis
become_user : '{{ pg_user }}'
become : true
postgresql_ext :
db : postgres
name : postgis
schema : schema1
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result is changed
- result.queries == ['CREATE EXTENSION "postgis" WITH SCHEMA "schema1"']
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - check that extension exists after the previous step
become_user : '{{ pg_user }}'
become : true
postgresql_query :
db : postgres
query : "SELECT extname FROM pg_extension AS e LEFT JOIN pg_catalog.pg_namespace AS n \nON n.oid = e.extnamespace WHERE e.extname='postgis' AND n.nspname='schema1'\n"
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result.rowcount == 1
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - drop extension postgis cascade
become_user : '{{ pg_user }}'
become : true
postgresql_ext :
db : postgres
name : postgis
state : absent
cascade : true
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result is changed
- result.queries == ['DROP EXTENSION "postgis" CASCADE']
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - check that extension doesn't exist after the previous step
become_user : '{{ pg_user }}'
become : true
postgresql_query :
db : postgres
query : SELECT extname FROM pg_extension WHERE extname='postgis'
ignore_errors : true
register : result
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result.rowcount == 0
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - create extension postgis cascade
become_user : '{{ pg_user }}'
become : true
postgresql_ext :
db : postgres
name : postgis
cascade : true
ignore_errors : true
register : result
when : postgres_version_resp.stdout is version('9.6', '<=')
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result is changed
- result.queries == ['CREATE EXTENSION "postgis" CASCADE"']
when : postgres_version_resp.stdout is version('9.6', '<=')
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- name : postgresql_ext - check that extension exists after the previous step
become_user : '{{ pg_user }}'
become : true
postgresql_query :
db : postgres
query : SELECT extname FROM pg_extension WHERE extname='postgis'
ignore_errors : true
register : result
when : postgres_version_resp.stdout is version('9.6', '<=')
2020-05-05 14:04:33 +02:00
2020-03-09 10:11:07 +01:00
- assert :
that :
- result.rowcount == 1
when : postgres_version_resp.stdout is version('9.6', '<=')
2020-05-05 14:04:33 +02:00
- name : postgresql_ext - check that using a dangerous name fails
postgresql_ext :
db : postgres
name : postgis
session_role : 'curious.anonymous"; SELECT * FROM information_schema.tables; --'
trust_input : no
ignore_errors : true
register : result
- assert :
that :
- result is failed
- result.msg is search('is potentially dangerous')