Skip to content

Commit

Permalink
add use_proxy option variable && get GPG KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Mar 26, 2021
1 parent 222a9d4 commit 36d9701
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 20 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,20 @@ Set postgresql databases and users to create if not set create_users: no and cre
Example of creating multiple databases and users:
```Yaml
postgresql_databases_users:
- {database: test, user: user1, userpassword: user1pass, priv: ALL} #add database 'user' and user 'user1' with password 'user1pass' with Privileges 'ALL'
- {database: test1, user:'', userpassword: '', priv: ''} #add only database 'test1'
- {database: '', user: user2, userpassword: user2pass, priv: ''} #add only user 'user2' with password 'user2pass'
postgresql_databases_users: []
#postgresql_databases_users:
# - {database: test, user: user1, userpassword: user1pass, priv: ALL} #add database 'user' and user 'user1' with password 'user1pass' with Privileges 'ALL'
# - {database: test1, user:'', userpassword: '', priv: ''} #add only database 'test1'
# - {database: '', user: user2, userpassword: user2pass, priv: ''} #add only user 'user2' with password 'user2pass'
```
- To create only database without user set database: name, user:''
- To create only user set database: '', user: name, userpassword: password
- To create database with user PRIVILEGES set database: name, user: name, userpassword: password, priv: privileges
- To create only database without user set database: databasename, user:''
- To create only user set database: '', user: username, userpassword: password
- To create database with user PRIVILEGES set database: databasename, user: username, userpassword: password, priv: privileges
### Basic configuration

| Variable | Default | Comments |
| :--- | :--- | :--- |
| `use_proxy ` | 'False' | If managed hosts are behind web proxy set use_proxy: True |
| `http_proxy ` | 'http://proxy.lab.local:8080/'| Set Proxy server and port replace proxy.lab.local:8080 |
| `https_proxy` | 'http://proxy.lab.local:8080/'| Set Proxy server and port replace proxy.lab.local:8080 |
| `postgresql_version` | | Postgresql version that will be installed |
Expand All @@ -61,9 +63,12 @@ postgresql_databases_users:

#### Remarks

(1) Remove the folowing parameters on all install packages tasks if machines have an internet access without proxy server .:
(1) If managed hosts are behind web proxy set the folowing variables in defaults/main.yml file:
```yaml
environment: "{{ proxy_env }}"
use_proxy: False
proxy_env:
http_proxy: http://proxy.local:8080/
https_proxy: http://proxy.local:8080/
```
## Example Playbook
Expand Down
8 changes: 7 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ create_databases: true
pgsql_supported_version: ['9.5', '9.6', '10', '11', '12', '13']
configure_firewalld_for_redhat: true
check_selinux: true
listen_addresses_host_ip: true
listen_addresses_host_ip: true
use_proxy: False
proxy_env: []
#example:
#proxy_env:
# http_proxy: http://proxy.local:8080/
# https_proxy: http://proxy.local:8080/
9 changes: 8 additions & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@

- name: Apt Update
apt: update_cache=yes force_apt_get=yes
environment: "{{ proxy_env }}"
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: Apt Update
apt: update_cache=yes force_apt_get=yes
when: (use_proxy is not defined) or (not use_proxy)
28 changes: 28 additions & 0 deletions tasks/Debian-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
state: present
notify: Apt Update
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: add posgresql repository key
apt_key:
url: "{{ key_url }}"
state: present
notify: Apt Update
when: (use_proxy is not defined) or (not use_proxy)

- meta: flush_handlers

Expand All @@ -25,12 +35,30 @@
name: "{{ postgresql_packages_prereq }}"
state: present
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: install ansible prerequisites
apt:
name: "{{ postgresql_packages_prereq }}"
state: present
when: (use_proxy is not defined) or (not use_proxy)

- name: install postgresql packages
apt:
name: "{{ postgresql_packages }}"
state: present
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: install postgresql packages
apt:
name: "{{ postgresql_packages }}"
state: present
when: (use_proxy is not defined) or (not use_proxy)

- name: Check if Postgresql {{ postgresql_version }} is already initialized
stat:
Expand Down
75 changes: 73 additions & 2 deletions tasks/RedHat-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,79 @@
src: pgdg-redhat.repo.j2
dest: /etc/yum.repos.d/pgdg-redhat.repo

- name: get pgdg RMP GPG KEY
rpm_key:
state: present
key: https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: get pgdg RMP GPG KEY
rpm_key:
state: present
key: https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG
when: (use_proxy is not defined) or (not use_proxy)

- name: install ansible prerequisites
package:
name: "python{{ ansible_python_version is version('3.0.0', '<') | ternary('2', '3') }}-psycopg2"
state: present
disablerepo: "*"
enablerepo: "pgdg{{ postgresql_version | replace('.','') }}"
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: install ansible prerequisites
package:
name: "python{{ ansible_python_version is version('3.0.0', '<') | ternary('2', '3') }}-psycopg2"
state: present
disablerepo: "*"
enablerepo: "pgdg{{ postgresql_version | replace('.','') }}"
when: (use_proxy is not defined) or (not use_proxy)

- name: install selinux tools
package:
name: "policycoreutils-python"
state: present
environment: "{{ proxy_env }}"
when: ansible_distribution_file_variety == "RedHat" and ansible_distribution_major_version == "7"
when:
- ansible_distribution_file_variety == "RedHat"
- ansible_distribution_major_version == "7"
- use_proxy is defined
- use_proxy

- name: install selinux tools
package:
name: "policycoreutils-python"
state: present
when:
- ansible_distribution_file_variety == "RedHat"
- ansible_distribution_major_version == "7"
- (use_proxy is not defined) or (not use_proxy)

- name: install selinux tools
package:
name: "policycoreutils-python-utils"
state: present
environment: "{{ proxy_env }}"
when: ansible_distribution_file_variety == "RedHat" and ansible_distribution_major_version == "8"
when:
- ansible_distribution_file_variety == "RedHat"
- ansible_distribution_major_version == "8"
- use_proxy is defined
- use_proxy

- name: install selinux tools
package:
name: "policycoreutils-python-utils"
state: present
when:
- ansible_distribution_file_variety == "RedHat"
- ansible_distribution_major_version == "8"
- (use_proxy is not defined) or (not use_proxy)

- name: disable dnf postgresql default module
command: dnf module -y disable postgresql
Expand All @@ -44,12 +96,31 @@
dest: "/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG"
validate_certs: no
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: ensure RPM-GPG-KEY-PGDG file exist
get_url:
url: "https://download.postgresql.org/pub/repos/yum/RPM-GPG-KEY-PGDG"
dest: "/etc/pki/rpm-gpg/RPM-GPG-KEY-PGDG"
validate_certs: no
when: (use_proxy is not defined) or (not use_proxy)

- name: Install Postgresql {{ postgresql_version }} packages
package:
name: "{{ postgresql_packages }}"
state: present
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: Install Postgresql {{ postgresql_version }} packages
package:
name: "{{ postgresql_packages }}"
state: present
when: (use_proxy is not defined) or (not use_proxy)

- name: set fact posgresql bin setup file
set_fact:
Expand Down
9 changes: 9 additions & 0 deletions tasks/SUSE-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
name: "{{ postgresql_packages }}"
state: present
environment: "{{ proxy_env }}"
when:
- use_proxy is defined
- use_proxy

- name: install Postgresql {{ postgresql_version }} packages
zypper:
name: "{{ postgresql_packages }}"
state: present
when: (use_proxy is not defined) or (not use_proxy)

- name: set fact posgresql bin setup file
set_fact:
Expand Down
12 changes: 5 additions & 7 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---
# vars file for postgresql
proxy_env:
http_proxy: http://proxy.lab.local:8080/
https_proxy: http://proxy.lab.local:8080/

postgresql_host: "localhost"
postgresql_user: "postgres"
Expand All @@ -25,7 +22,8 @@ postgresql_authentication:
- {type: host, database: replication, user: all, address: '127.0.0.1/32', auth_method: md5}
- {type: host, database: replication, user: all, address: '::1/128', auth_method: md5}

postgresql_databases_users:
- {database: test, user: user1, userpassword: user1pass, priv: ALL}
- {database: test1, user: '', userpassword: '', priv: ''}
- {database: '', user: user2, userpassword: user2pass, priv: ''}
postgresql_databases_users: []
#postgresql_databases_users:
# - {database: test, user: user1, userpassword: user1pass, priv: ALL}
# - {database: test1, user: '', userpassword: '', priv: ''}
# - {database: '', user: user2, userpassword: user2pass, priv: ''}

0 comments on commit 36d9701

Please sign in to comment.