Skip to content

Commit 81a7334

Browse files
committed
Initial commit
0 parents  commit 81a7334

15 files changed

+219
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.DS_Store
2+
.AppleDouble
3+
.LSOverride
4+
Icon
5+
._*
6+
.Spotlight-V100
7+
.Trashes
8+
.vagrant
9+
test

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
language: python
3+
python: "2.7"
4+
before_install:
5+
- sudo apt-get update -qq
6+
- sudo apt-get install -qq python-apt python-pycurl
7+
install:
8+
- pip install ansible==1.5.0
9+
script:
10+
- echo localhost > inventory
11+
- ansible-playbook --syntax-check -i inventory test.yml
12+
- ansible-playbook -i inventory test.yml --connection=local --sudo

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License
2+
3+
Copyright (c) 2014 Pieterjan Vandaele
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Ansibles - PostgreSQL [![Build Status](https://travis-ci.org/Ansibles/postgresql.png)](https://travis-ci.org/Ansibles/postgresql)
2+
3+
Ansible role for installing and configuring PostgreSQL.
4+
5+
6+
#### Requirements & Dependencies
7+
- Tested on Ansible 1.4 or higher.
8+
- Ansibles.monit if you want monit protection (in that case, you should set `monit_protection: true`)
9+
10+
11+
#### Variables
12+
13+
```yaml
14+
...
15+
```
16+
17+
#### License
18+
19+
Licensed under the MIT License. See the LICENSE file for details.
20+
21+
#### Feedback, bug-reports, requests, ...
22+
23+
Are [welcome](https://github.com/ansibles/postgresql/issues)!

defaults/main.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# file: postgresql/defaults/main.yml
2+
3+
# Basic settings
4+
postgresql_version: 9.3
5+
postgresql_encoding: 'UTF-8'
6+
postgresql_locale: 'en_US.UTF-8'
7+
8+
postgresql_admin_user: "postgres"
9+
postgresql_default_auth_method: "trust"
10+
11+
postgresql_cluster_name: "main"
12+
postgresql_cluster_reset: false
13+
14+
# pg_hba.conf
15+
postgresql_pg_hba_default:
16+
- { type: local, database: all, user: '{{ postgresql_admin_user }}', address: '', method: '{{ postgresql_defualt_auth_method }}', comment: '' }
17+
- { type: local, database: all, user: all, address: '', method: '{{ postgresql_defualt_auth_method }}', comment: '"local" is for Unix domain socket connections only' }
18+
- { type: host, database: all, user: all, address: '127.0.0.1/32', method: '{{ postgresql_defualt_auth_method }}', comment: 'IPv4 local connections:' }
19+
- { type: host, database: all, user: all, address: '::1/128', method: '{{ postgresql_defualt_auth_method }}', comment: 'IPv6 local connections:' }
20+
21+
postgresql_pg_hba_passwd_hosts: []
22+
postgresql_pg_hba_trust_hosts: []
23+
postgresql_pg_hba_custom: []
24+
25+
26+
27+
postgresql_env:
28+
LC_ALL: "{{ postgresql_locale }}"
29+
LC_LCTYPE: "{{ postgresql_locale }}"

handlers/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# file: postgresql/handlers/main.yml
2+
3+
- name: restart postgresql
4+
service:
5+
name: postgresql
6+
state: restarted

meta/main.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# file: postgresql/meta/main.yml
2+
3+
galaxy_info:
4+
author: pjan vandaele
5+
description: Install and configure PostgreSQL, dependencies and extensions
6+
min_ansible_version: 1.4
7+
license: MIT
8+
platforms:
9+
- name: Ubuntu
10+
versions:
11+
- all
12+
categories:
13+
- database
14+
- database:SQL
15+
16+
dependencies: []

tasks/configure.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# file: postgresql/tasks/configure.yml
2+
3+
- name: PostgreSQL | Reset the cluster - drop the existing one
4+
shell: pg_dropcluster --stop {{postgresql_version}} {{postgresql_cluster_name}}
5+
sudo: yes
6+
sudo_user: postgresql
7+
when: postgresql_cluster_reset
8+
9+
- name: PostgreSQL | Reset the cluster - create a new one (with specified encoding and locale)
10+
shell: pg_createcluster --start --locale {{postgresql_locale}} -e {{postgresql_encoding}} {{postgresql_version}} {{postgresql_cluster_name}}
11+
sudo: yes
12+
sudo_user: postgresql
13+
when: postgresql_cluster_reset
14+
15+
- name: PostgreSQL | Update configuration - pt. 1 (pg_hba.conf)
16+
template:
17+
src: etc_postgresql_version_cluster_pg_hba.conf.j2
18+
dest: "/etc/postgresql/{{postgresql_version}}/{{postgresql_cluster_name}}/pg_hba.conf"
19+
owner: "{{postgresql_admin_user}}"
20+
group: "{{postgresql_admin_user}}"
21+
mode: 0640
22+
notify:
23+
- restart postgresql

tasks/databases.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# file: postgresql/tasks/databases.yml

tasks/install.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# file: postgresql/tasks/install.yml
2+
3+
- name: PostgreSQL | Make sure the dependencies are installed
4+
apt:
5+
pkg: "{{item}}"
6+
state: present
7+
with_items:
8+
- python-psycopg2
9+
10+
- name: PostgreSQL | Add PostgeSQL repository apt-key
11+
apt_key:
12+
url: "https://www.postgresql.org/media/keys/ACCC4CF8.asc"
13+
state: present
14+
15+
- name: PostgreSQL | Add PostgreSQL repository
16+
apt_repository:
17+
repo: 'deb http://apt.postgresql.org/pub/repos/apt/ {{ansible_distribution_release}}-pgdg main'
18+
state: present
19+
20+
- name: PostgreSQL | Install PostgreSQL
21+
apt:
22+
name: "{{item}}"
23+
state: present
24+
environment: postgresql_env
25+
with_items:
26+
- "postgresql-{{postgresql_version}}"
27+
- "postgresql-client-{{postgresql_version}}"

tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# file: postgresql/tasks/main.yml
2+
3+
- include: install.yml
4+
- include: configure.yml

tasks/monit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# file: postgresql/tasks/monit.yml

tasks/users.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# file: postgresql/tasks/users.yml
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# PostgreSQL Client Authentication Configuration File
2+
# ===================================================
3+
#
4+
# Refer to the "Client Authentication" section in the PostgreSQL
5+
# documentation for a complete description of this file. A short
6+
# synopsis follows.
7+
#
8+
# This file controls: which hosts are allowed to connect, how clients
9+
# are authenticated, which PostgreSQL user names they can use, which
10+
# databases they can access. Records take one of these forms:
11+
#
12+
# local DATABASE USER METHOD [OPTIONS]
13+
# host DATABASE USER ADDRESS METHOD [OPTIONS]
14+
# hostssl DATABASE USER ADDRESS METHOD [OPTIONS]
15+
# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]
16+
#
17+
# TYPE DATABASE USER ADDRESS METHOD
18+
19+
# Default:
20+
{% for connection in postgresql_pg_hba_default %}
21+
# {{ connection.comment }}
22+
{{ connection.type }} {{ connection.database }} {{ connection.user }} {{ connection.address }} {{ connection.method }}
23+
{% endfor %}
24+
25+
# Passwored hosts
26+
{% for host in postgresql_pg_hba_passwd_hosts %}
27+
# {{ connection.comment }}
28+
host all all {{ host }} password
29+
{% endfor %}
30+
31+
# Trusted hosts
32+
{% for host in postgresql_pg_hba_trust_hosts %}
33+
# {{ connection.comment }}
34+
host all all {{ host }} trust
35+
{% endfor %}
36+
37+
# User custom
38+
{% for connection in postgresql_pg_hba_custom %}
39+
# {{ connection.comment }}
40+
{{ connection.type }} {{ connection.database }} {{ connection.user }} {{ connection.address }} {{ connection.method }}
41+
{% endfor %}

test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- hosts: all
2+
vars_files:
3+
- 'defaults/main.yml'
4+
tasks:
5+
- include: 'tasks/main.yml'

0 commit comments

Comments
 (0)