Skip to content

Commit 113f769

Browse files
authored
Merge pull request #45 from galaxyproject/psycopg2
Automatically install psycopg2
2 parents cffcfd9 + 5d98f48 commit 113f769

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ PostgreSQL
33

44
An [Ansible][ansible] role for installing and managing [PostgreSQL][postgresql] servers. This role works with both
55
Debian and RedHat based systems, and provides backup scripts for [PostgreSQL Continuous Archiving and Point-in-Time
6-
Recovery][postgresql_pitr].
6+
Recovery][postgresql_pitr]. It does not create or manage PostgreSQL users, roles, groups, databases, and so forth. For
7+
that, see [galaxyproject.postgresql_objects][postgresql_objects].
78

89
On RedHat-based platforms, the [PostgreSQL Global Development Group (PGDG) packages][pgdg_yum] packages will be
910
installed. On Debian-based platforms, you can choose from the distribution's packages (from APT) or the [PGDG
@@ -12,6 +13,7 @@ packages][pgdg_apt].
1213
[ansible]: http://www.ansible.com/
1314
[postgresql]: http://www.postgresql.org/
1415
[postgresql_pitr]: http://www.postgresql.org/docs/9.4/static/continuous-archiving.html
16+
[postgresql_objects]: https://github.com/galaxyproject/ansible-postgresql-objects/
1517
[pgdg_yum]: http://yum.postgresql.org/
1618
[pgdg_apt]: http://apt.postgresql.org/
1719

@@ -83,6 +85,10 @@ Role Variables
8385
8486
- `postgresql_conf_dir`: As with `postgresql_pgdata` except for the configuration directory.
8587
88+
- `postgresql_install_psycopg2`: Attempt to install the correct pacakge providing psycopg2 to the Python interpreter
89+
that Ansible is using on the remote side. This allows for the use of the `postgresql_*` Ansible modules (perhaps via
90+
[galaxyproject.postgresql_objects][postgresql_objects]), which depend on psycopg2. Defaults to `true`.
91+
8692
### Backups ###
8793
8894
- `postgresql_backup_dir`: If set, enables [PITR][postgresql_pitr] backups. Set this to a directory where your database
@@ -173,4 +179,4 @@ License
173179
Author Information
174180
------------------
175181

176-
[Nate Coraor](https://github.com/natefoo)
182+
The [Galaxy Community](https://galaxyproject.org/) and [contributors](https://github.com/galaxyproject/ansible-postgresql/graphs/contributors)

defaults/main.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ postgresql_pgdg_key_dest: "{{ postgresql_apt_keys_dir }}/pgdg.asc"
55
postgresql_pgdg_key_url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
66
postgresql_pgdg_repo: "deb [signed-by={{ postgresql_pgdg_key_dest }}] http://apt.postgresql.org/pub/repos/apt/ {{ ansible_distribution_release }}-pgdg main"
77

8-
postgresql_default_version: 10
8+
postgresql_default_version: 15
99
postgresql_user_name: postgres
1010

11+
postgresql_install_psycopg2: true
12+
1113
# Point-In-Time Recovery (PITR) backup options
1214
# https://www.postgresql.org/docs/current/continuous-archiving.html
1315
postgresql_backup_local_dir: >-

tasks/debian.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@
4040
set_fact:
4141
postgresql_version: "{{ __postgresql_version_query_result.stdout.split('+') | first }}"
4242
when: postgresql_version is not defined
43+
44+
- name: Install psycopg2
45+
apt:
46+
name: "python{{ (ansible_python.version.major == 3) | ternary('3', '') }}-psycopg2"
47+
when: postgresql_install_psycopg2

tasks/redhat.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@
7272
when: >-
7373
ansible_distribution_major_version is version(7, '>=')
7474
and (pgdata_stat.stat.isdir is not defined or not pgdata_stat.stat.isdir)
75+
76+
- name: Install psycopg2
77+
yum:
78+
name: "python{{ ansible_python.version.major }}-psycopg2"
79+
when: postgresql_install_psycopg2

0 commit comments

Comments
 (0)