mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-03 06:49:10 -07:00
Initial commit
This commit is contained in:
commit
aebc1b03fd
4861 changed files with 812621 additions and 0 deletions
|
@ -0,0 +1,17 @@
|
|||
postgresql_service: postgresql
|
||||
|
||||
postgresql_packages:
|
||||
- postgresql-server
|
||||
- python-psycopg2
|
||||
|
||||
pg_user: postgres
|
||||
pg_group: root
|
||||
|
||||
locale_latin_suffix:
|
||||
locale_utf8_suffix:
|
||||
|
||||
# defaults for test SSL
|
||||
ssl_db: 'ssl_db'
|
||||
ssl_user: 'ssl_user'
|
||||
ssl_pass: 'ssl_pass'
|
||||
ssl_rootcert: '~{{ pg_user }}/root.crt'
|
|
@ -0,0 +1,2 @@
|
|||
CREATE OR REPLACE FUNCTION dummy_display_ext_version()
|
||||
RETURNS text LANGUAGE SQL AS 'SELECT (''1.0'')::text';
|
|
@ -0,0 +1,2 @@
|
|||
CREATE OR REPLACE FUNCTION dummy_display_ext_version()
|
||||
RETURNS text LANGUAGE SQL AS 'SELECT (''2.0'')::text';
|
|
@ -0,0 +1,2 @@
|
|||
CREATE OR REPLACE FUNCTION dummy_display_ext_version()
|
||||
RETURNS text LANGUAGE SQL AS 'SELECT (''3.0'')::text';
|
|
@ -0,0 +1,3 @@
|
|||
comment = 'dummy extension used to test postgresql_ext Ansible module'
|
||||
default_version = '3.0'
|
||||
relocatable = true
|
|
@ -0,0 +1,10 @@
|
|||
# !!! This file managed by Ansible. Any local changes may be overwritten. !!!
|
||||
|
||||
# Database administrative login by UNIX sockets
|
||||
# note: you may wish to restrict this further later
|
||||
local all {{ pg_user }} trust
|
||||
|
||||
# TYPE DATABASE USER CIDR-ADDRESS METHOD
|
||||
local all all md5
|
||||
host all all 127.0.0.1/32 md5
|
||||
host all all ::1/128 md5
|
171
tests/integration/targets/setup_postgresql_db/tasks/main.yml
Normal file
171
tests/integration/targets/setup_postgresql_db/tasks/main.yml
Normal file
|
@ -0,0 +1,171 @@
|
|||
- name: python 2
|
||||
set_fact:
|
||||
python_suffix: ''
|
||||
when: ansible_python_version is version('3', '<')
|
||||
- name: python 3
|
||||
set_fact:
|
||||
python_suffix: -py3
|
||||
when: ansible_python_version is version('3', '>=')
|
||||
- name: Include distribution and Python version specific variables
|
||||
include_vars: '{{ lookup(''first_found'', params) }}'
|
||||
vars:
|
||||
params:
|
||||
files:
|
||||
- '{{ ansible_distribution }}-{{ ansible_distribution_major_version }}{{ python_suffix }}.yml'
|
||||
- '{{ ansible_distribution }}-{{ ansible_distribution_version }}{{ python_suffix }}.yml'
|
||||
- '{{ ansible_os_family }}{{ python_suffix }}.yml'
|
||||
- default{{ python_suffix }}.yml
|
||||
paths:
|
||||
- '{{ role_path }}/vars'
|
||||
- name: make sure the dbus service is started under systemd
|
||||
systemd:
|
||||
name: dbus
|
||||
state: started
|
||||
when: ansible_service_mgr == 'systemd' and ansible_distribution == 'Fedora'
|
||||
- name: stop postgresql service
|
||||
service: name={{ postgresql_service }} state=stopped
|
||||
ignore_errors: true
|
||||
- name: remove old db (RedHat or Suse)
|
||||
file:
|
||||
path: '{{ pg_dir }}'
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
when: ansible_os_family == "RedHat" or ansible_os_family == "Suse"
|
||||
- name: remove old db (FreeBSD)
|
||||
file:
|
||||
path: '{{ pg_dir }}'
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
when: ansible_os_family == "FreeBSD"
|
||||
- name: remove old db config and files (debian)
|
||||
file:
|
||||
path: '{{ loop_item }}'
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
when: ansible_os_family == "Debian"
|
||||
loop:
|
||||
- /etc/postgresql
|
||||
- /var/lib/postgresql
|
||||
loop_control:
|
||||
loop_var: loop_item
|
||||
- name: install dependencies for postgresql test
|
||||
package:
|
||||
name: '{{ postgresql_package_item }}'
|
||||
state: present
|
||||
with_items: '{{ postgresql_packages }}'
|
||||
loop_control:
|
||||
loop_var: postgresql_package_item
|
||||
- name: initialize postgres (FreeBSD)
|
||||
command: /usr/local/etc/rc.d/postgresql oneinitdb
|
||||
when: ansible_os_family == "FreeBSD"
|
||||
- name: Initialize postgres (RedHat systemd)
|
||||
command: postgresql-setup initdb
|
||||
when: ansible_os_family == "RedHat" and ansible_service_mgr == "systemd"
|
||||
- name: Initialize postgres (RedHat sysv)
|
||||
command: /sbin/service postgresql initdb
|
||||
when: ansible_os_family == "RedHat" and ansible_service_mgr != "systemd"
|
||||
- name: Initialize postgres (Debian)
|
||||
shell: . /usr/share/postgresql-common/maintscripts-functions && set_system_locale && /usr/bin/pg_createcluster -u postgres {{ pg_ver }} main
|
||||
args:
|
||||
creates: /etc/postgresql/{{ pg_ver }}/
|
||||
when: ansible_os_family == 'Debian'
|
||||
- name: Initialize postgres (Suse)
|
||||
service: name=postgresql state=restarted
|
||||
when: ansible_os_family == 'Suse'
|
||||
- name: Copy pg_hba into place
|
||||
template:
|
||||
src: files/pg_hba.conf
|
||||
dest: '{{ pg_hba_location }}'
|
||||
owner: '{{ pg_user }}'
|
||||
group: '{{ pg_group }}'
|
||||
mode: '0644'
|
||||
- name: Generate locales (Debian)
|
||||
locale_gen:
|
||||
name: '{{ item }}'
|
||||
state: present
|
||||
with_items:
|
||||
- pt_BR
|
||||
- es_ES
|
||||
when: ansible_os_family == 'Debian'
|
||||
- block:
|
||||
- name: Install langpacks (RHEL8)
|
||||
yum:
|
||||
name:
|
||||
- glibc-langpack-es
|
||||
- glibc-langpack-pt
|
||||
- glibc-all-langpacks
|
||||
state: present
|
||||
when: ansible_distribution_major_version is version('8', '>=')
|
||||
- name: Check if locales need to be generated (RedHat)
|
||||
shell: localedef --list-archive | grep -a -q '^{{ locale }}$'
|
||||
register: locale_present
|
||||
ignore_errors: true
|
||||
with_items:
|
||||
- es_ES
|
||||
- pt_BR
|
||||
loop_control:
|
||||
loop_var: locale
|
||||
- name: Reinstall internationalization files
|
||||
shell: yum -y reinstall glibc-common || yum -y install glibc-common
|
||||
args:
|
||||
warn: false
|
||||
when: locale_present is failed
|
||||
- name: Generate locale (RedHat)
|
||||
command: localedef -f ISO-8859-1 -i {{ item.locale }} {{ item.locale }}
|
||||
when: item is failed
|
||||
with_items: '{{ locale_present.results }}'
|
||||
when: ansible_os_family == 'RedHat' and ansible_distribution != 'Fedora'
|
||||
- name: Install glibc langpacks (Fedora >= 24)
|
||||
package:
|
||||
name: '{{ item }}'
|
||||
state: latest
|
||||
with_items:
|
||||
- glibc-langpack-es
|
||||
- glibc-langpack-pt
|
||||
when: ansible_distribution == 'Fedora' and ansible_distribution_major_version is version('24', '>=')
|
||||
- name: enable postgresql service (FreeBSD)
|
||||
lineinfile:
|
||||
path: /etc/rc.conf
|
||||
line: postgresql_enable="YES"
|
||||
when: ansible_os_family == "FreeBSD"
|
||||
- name: start postgresql service
|
||||
service: name={{ postgresql_service }} state=started
|
||||
- name: restart postgresql service
|
||||
service: name={{ postgresql_service }} state=restarted
|
||||
- name: copy control file for dummy ext
|
||||
copy:
|
||||
src: dummy.control
|
||||
dest: /usr/share/postgresql/{{ pg_ver }}/extension/dummy.control
|
||||
mode: '0444'
|
||||
when: ansible_os_family == 'Debian'
|
||||
- name: copy version files for dummy ext
|
||||
copy:
|
||||
src: '{{ item }}'
|
||||
dest: /usr/share/postgresql/{{ pg_ver }}/extension/{{ item }}
|
||||
mode: '0444'
|
||||
with_items:
|
||||
- dummy--1.0.sql
|
||||
- dummy--2.0.sql
|
||||
- dummy--3.0.sql
|
||||
when: ansible_os_family == 'Debian'
|
||||
- name: add update paths
|
||||
file:
|
||||
path: /usr/share/postgresql/{{ pg_ver }}/extension/{{ item }}
|
||||
mode: '0444'
|
||||
state: touch
|
||||
with_items:
|
||||
- dummy--1.0--2.0.sql
|
||||
- dummy--2.0--3.0.sql
|
||||
when: ansible_os_family == 'Debian'
|
||||
- name: Get PostgreSQL version
|
||||
become_user: '{{ pg_user }}'
|
||||
become: true
|
||||
shell: echo 'SHOW SERVER_VERSION' | psql --tuples-only --no-align --dbname postgres
|
||||
register: postgres_version_resp
|
||||
- name: Print PostgreSQL server version
|
||||
debug:
|
||||
msg: '{{ postgres_version_resp.stdout }}'
|
||||
- import_tasks: ssl.yml
|
||||
when:
|
||||
- ansible_os_family == 'Debian'
|
||||
- postgres_version_resp.stdout is version('9.4', '>=')
|
57
tests/integration/targets/setup_postgresql_db/tasks/ssl.yml
Normal file
57
tests/integration/targets/setup_postgresql_db/tasks/ssl.yml
Normal file
|
@ -0,0 +1,57 @@
|
|||
- name: postgresql SSL - create database
|
||||
become_user: '{{ pg_user }}'
|
||||
become: true
|
||||
postgresql_db:
|
||||
name: '{{ ssl_db }}'
|
||||
- name: postgresql SSL - create role
|
||||
become_user: '{{ pg_user }}'
|
||||
become: true
|
||||
postgresql_user:
|
||||
name: '{{ ssl_user }}'
|
||||
role_attr_flags: SUPERUSER
|
||||
password: '{{ ssl_pass }}'
|
||||
- name: postgresql SSL - install openssl
|
||||
become: true
|
||||
package: name=openssl state=present
|
||||
- name: postgresql SSL - create certs 1
|
||||
become_user: root
|
||||
become: true
|
||||
shell: openssl req -new -nodes -text -out ~{{ pg_user }}/root.csr \ -keyout ~{{ pg_user }}/root.key -subj "/CN=localhost.local"
|
||||
- name: postgresql SSL - create certs 2
|
||||
become_user: root
|
||||
become: true
|
||||
shell: openssl x509 -req -in ~{{ pg_user }}/root.csr -text -days 3650 \ -extensions v3_ca -signkey ~{{ pg_user }}/root.key -out ~{{ pg_user }}/root.crt
|
||||
- name: postgresql SSL - create certs 3
|
||||
become_user: root
|
||||
become: true
|
||||
shell: openssl req -new -nodes -text -out ~{{ pg_user }}/server.csr \ -keyout ~{{ pg_user }}/server.key -subj "/CN=localhost.local"
|
||||
- name: postgresql SSL - create certs 4
|
||||
become_user: root
|
||||
become: true
|
||||
shell: openssl x509 -req -in ~{{ pg_user }}/server.csr -text -days 365 \ -CA ~{{ pg_user }}/root.crt -CAkey ~{{ pg_user }}/root.key -CAcreateserial -out server.crt
|
||||
- name: postgresql SSL - set right permissions to files
|
||||
become_user: root
|
||||
become: true
|
||||
file:
|
||||
path: '{{ item }}'
|
||||
mode: '0600'
|
||||
owner: '{{ pg_user }}'
|
||||
group: '{{ pg_user }}'
|
||||
with_items:
|
||||
- ~{{ pg_user }}/root.key
|
||||
- ~{{ pg_user }}/server.key
|
||||
- ~{{ pg_user }}/root.crt
|
||||
- ~{{ pg_user }}/server.csr
|
||||
- name: postgresql SSL - enable SSL
|
||||
become_user: '{{ pg_user }}'
|
||||
become: true
|
||||
postgresql_set:
|
||||
login_user: '{{ pg_user }}'
|
||||
db: postgres
|
||||
name: ssl
|
||||
value: true
|
||||
- name: postgresql SSL - reload PostgreSQL to enable ssl on
|
||||
become: true
|
||||
service:
|
||||
name: '{{ postgresql_service }}'
|
||||
state: reloaded
|
|
@ -0,0 +1,8 @@
|
|||
postgresql_packages:
|
||||
- "postgresql"
|
||||
- "postgresql-common"
|
||||
- "python-psycopg2"
|
||||
|
||||
pg_hba_location: "/etc/postgresql/9.4/main/pg_hba.conf"
|
||||
pg_dir: "/var/lib/postgresql/9.4/main"
|
||||
pg_ver: 9.4
|
|
@ -0,0 +1,12 @@
|
|||
postgresql_packages:
|
||||
- postgresql95-server
|
||||
- py36-psycopg2
|
||||
|
||||
pg_dir: /usr/local/pgsql/data
|
||||
pg_hba_location: "{{ pg_dir }}/pg_hba.conf"
|
||||
pg_ver: 9.5
|
||||
pg_user: pgsql
|
||||
pg_group: pgsql
|
||||
|
||||
locale_latin_suffix: .ISO8859-1
|
||||
locale_utf8_suffix: .UTF-8
|
|
@ -0,0 +1,12 @@
|
|||
postgresql_packages:
|
||||
- postgresql95-server
|
||||
- py27-psycopg2
|
||||
|
||||
pg_dir: /usr/local/pgsql/data
|
||||
pg_hba_location: "{{ pg_dir }}/pg_hba.conf"
|
||||
pg_ver: 9.5
|
||||
pg_user: pgsql
|
||||
pg_group: pgsql
|
||||
|
||||
locale_latin_suffix: .ISO8859-1
|
||||
locale_utf8_suffix: .UTF-8
|
|
@ -0,0 +1,12 @@
|
|||
postgresql_packages:
|
||||
- postgresql95-server
|
||||
- py36-psycopg2
|
||||
|
||||
pg_dir: /usr/local/pgsql/data
|
||||
pg_hba_location: "{{ pg_dir }}/pg_hba.conf"
|
||||
pg_ver: 9.5
|
||||
pg_user: pgsql
|
||||
pg_group: pgsql
|
||||
|
||||
locale_latin_suffix: .ISO8859-1
|
||||
locale_utf8_suffix: .UTF-8
|
|
@ -0,0 +1,12 @@
|
|||
postgresql_packages:
|
||||
- postgresql96-server
|
||||
- py27-psycopg2
|
||||
|
||||
pg_dir: /usr/local/pgsql/data
|
||||
pg_hba_location: "{{ pg_dir }}/pg_hba.conf"
|
||||
pg_ver: 9.6
|
||||
pg_user: pgsql
|
||||
pg_group: pgsql
|
||||
|
||||
locale_latin_suffix: .ISO8859-1
|
||||
locale_utf8_suffix: .UTF-8
|
|
@ -0,0 +1,12 @@
|
|||
postgresql_packages:
|
||||
- postgresql11-server
|
||||
- py36-psycopg2
|
||||
|
||||
pg_dir: /var/db/postgres/data11
|
||||
pg_hba_location: "{{ pg_dir }}/pg_hba.conf"
|
||||
pg_ver: 11
|
||||
pg_user: postgres
|
||||
pg_group: postgres
|
||||
|
||||
locale_latin_suffix: .ISO8859-1
|
||||
locale_utf8_suffix: .UTF-8
|
|
@ -0,0 +1,12 @@
|
|||
postgresql_packages:
|
||||
- postgresql11-server
|
||||
- py27-psycopg2
|
||||
|
||||
pg_dir: /var/db/postgres/data11
|
||||
pg_hba_location: "{{ pg_dir }}/pg_hba.conf"
|
||||
pg_ver: 11
|
||||
pg_user: postgres
|
||||
pg_group: postgres
|
||||
|
||||
locale_latin_suffix: .ISO8859-1
|
||||
locale_utf8_suffix: .UTF-8
|
|
@ -0,0 +1,8 @@
|
|||
postgresql_packages:
|
||||
- "postgresql-server"
|
||||
- "python3-psycopg2"
|
||||
- "bzip2"
|
||||
- "xz"
|
||||
|
||||
pg_hba_location: "/var/lib/pgsql/data/pg_hba.conf"
|
||||
pg_dir: "/var/lib/pgsql/data"
|
|
@ -0,0 +1,7 @@
|
|||
postgresql_packages:
|
||||
- "postgresql-server"
|
||||
- "python-psycopg2"
|
||||
- "bzip2"
|
||||
|
||||
pg_hba_location: "/var/lib/pgsql/data/pg_hba.conf"
|
||||
pg_dir: "/var/lib/pgsql/data"
|
|
@ -0,0 +1,8 @@
|
|||
postgresql_packages:
|
||||
- "postgresql"
|
||||
- "postgresql-common"
|
||||
- "python-psycopg2"
|
||||
|
||||
pg_hba_location: "/etc/postgresql/9.1/main/pg_hba.conf"
|
||||
pg_dir: "/var/lib/postgresql/9.1/main"
|
||||
pg_ver: 9.1
|
|
@ -0,0 +1,8 @@
|
|||
postgresql_packages:
|
||||
- "postgresql"
|
||||
- "postgresql-common"
|
||||
- "python-psycopg2"
|
||||
|
||||
pg_hba_location: "/etc/postgresql/9.3/main/pg_hba.conf"
|
||||
pg_dir: "/var/lib/postgresql/9.3/main"
|
||||
pg_ver: 9.3
|
|
@ -0,0 +1,8 @@
|
|||
postgresql_packages:
|
||||
- "postgresql"
|
||||
- "postgresql-common"
|
||||
- "python3-psycopg2"
|
||||
|
||||
pg_hba_location: "/etc/postgresql/9.5/main/pg_hba.conf"
|
||||
pg_dir: "/var/lib/postgresql/9.5/main"
|
||||
pg_ver: 9.5
|
|
@ -0,0 +1,8 @@
|
|||
postgresql_packages:
|
||||
- "postgresql"
|
||||
- "postgresql-common"
|
||||
- "python-psycopg2"
|
||||
|
||||
pg_hba_location: "/etc/postgresql/9.5/main/pg_hba.conf"
|
||||
pg_dir: "/var/lib/postgresql/9.5/main"
|
||||
pg_ver: 9.5
|
|
@ -0,0 +1,8 @@
|
|||
postgresql_packages:
|
||||
- "postgresql"
|
||||
- "postgresql-common"
|
||||
- "python3-psycopg2"
|
||||
|
||||
pg_hba_location: "/etc/postgresql/10/main/pg_hba.conf"
|
||||
pg_dir: "/var/lib/postgresql/10/main"
|
||||
pg_ver: 10
|
|
@ -0,0 +1,6 @@
|
|||
postgresql_packages:
|
||||
- "postgresql-server"
|
||||
- "python3-psycopg2"
|
||||
|
||||
pg_hba_location: "/var/lib/pgsql/data/pg_hba.conf"
|
||||
pg_dir: "/var/lib/pgsql/data"
|
|
@ -0,0 +1,6 @@
|
|||
postgresql_packages:
|
||||
- "postgresql-server"
|
||||
- "python-psycopg2"
|
||||
|
||||
pg_hba_location: "/var/lib/pgsql/data/pg_hba.conf"
|
||||
pg_dir: "/var/lib/pgsql/data"
|
Loading…
Add table
Add a link
Reference in a new issue