Skip to content

Commit c7c2ba8

Browse files
author
Julian Vanden Broeck
committed
Initial commit
0 parents  commit c7c2ba8

File tree

13 files changed

+331
-0
lines changed

13 files changed

+331
-0
lines changed

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Ansible Collection - l00ptr.postgres
2+
3+
## Description
4+
This collection provides roles to install, configure and manager your PostgreSQL infrastructure.
5+
6+
We try to keep variable name consistent between the roles composing this collection.
7+
8+
This collection is currently only available for Debian 9 and 10.
9+
10+
## Tested with Ansible
11+
12+
2.10
13+
14+
## Included content
15+
## Using this collection
16+
17+
Please refer to the examples in the readmes of the role.
18+
19+
See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for more details.
20+
21+
## Contributing to this collection
22+
23+
See the [contributor guideline](CONTRIBUTING.md).
24+
25+
## Roadmap
26+
- Add tests and CI testing
27+
- Add support for more operating systems,
28+
29+
## More information
30+
31+
General information:
32+
33+
- [Ansible Collection overview](https://github.com/ansible-collections/overview)
34+
- [Ansible User guide](https://docs.ansible.com/ansible/latest/user_guide/index.html)
35+
- [Ansible Developer guide](https://docs.ansible.com/ansible/latest/dev_guide/index.html)
36+
- [Ansible Collections Checklist](https://github.com/ansible-collections/overview/blob/master/collection_requirements.rst)
37+
- [Ansible Community code of conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html)
38+
- [The Bullhorn (the Ansible Contributor newsletter)](https://us19.campaign-archive.com/home/?u=56d874e027110e35dea0e03c1&id=d6635f5420)
39+
- [Changes impacting Contributors](https://github.com/ansible-collections/overview/issues/45)
40+
41+
## Licensing
42+
Released under MIT License
43+
44+
Copyright (c) 2020 Julian Vanden Broeck.
45+
46+
47+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
48+
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
49+
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
50+
51+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
52+
53+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
55+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
56+

galaxy.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
### REQUIRED
2+
3+
# The namespace of the collection. This can be a company/brand/organization or product namespace under which all
4+
# content lives. May only contain alphanumeric characters and underscores. Additionally namespaces cannot start with
5+
# underscores or numbers and cannot contain consecutive underscores
6+
namespace: l00ptr
7+
8+
# The name of the collection. Has the same character restrictions as 'namespace'
9+
name: postgres
10+
11+
# The version of the collection. Must be compatible with semantic versioning
12+
version: 1.0.0
13+
14+
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
15+
readme: README.md
16+
17+
# A list of the collection's content authors. Can be just the name or in the format 'Full Name <email> (url)
18+
# @nicks:irc/im.site#channel'
19+
authors:
20+
- your name <[email protected]>
21+
22+
23+
### OPTIONAL but strongly recommended
24+
25+
# A short summary description of the collection
26+
description: your collection description
27+
28+
# Either a single license or a list of licenses for content inside of a collection. Ansible Galaxy currently only
29+
# accepts L(SPDX,https://spdx.org/licenses/) licenses. This key is mutually exclusive with 'license_file'
30+
license:
31+
- GPL-2.0-or-later
32+
33+
# The path to the license file for the collection. This path is relative to the root of the collection. This key is
34+
# mutually exclusive with 'license'
35+
license_file: ''
36+
37+
# A list of tags you want to associate with the collection for indexing/searching. A tag name has the same character
38+
# requirements as 'namespace' and 'name'
39+
tags: []
40+
41+
# Collections that this collection requires to be installed for it to be usable. The key of the dict is the
42+
# collection label 'namespace.name'. The value is a version range
43+
# L(specifiers,https://python-semanticversion.readthedocs.io/en/latest/#requirement-specification). Multiple version
44+
# range specifiers can be set and are separated by ','
45+
dependencies: {}
46+
47+
# The URL of the originating SCM repository
48+
repository: http://example.com/repository
49+
50+
# The URL to any online docs
51+
documentation: http://docs.example.com
52+
53+
# The URL to the homepage of the collection/project
54+
homepage: http://example.com
55+
56+
# The URL to the collection issue tracker
57+
issues: http://example.com/issue/tracker

plugins/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Collections Plugins Directory
2+
3+
This directory can be used to ship various plugins inside an Ansible collection. Each plugin is placed in a folder that
4+
is named after the type of plugin it is in. It can also include the `module_utils` and `modules` directory that
5+
would contain module utils and modules respectively.
6+
7+
Here is an example directory of the majority of plugins currently supported by Ansible:
8+
9+
```
10+
└── plugins
11+
├── action
12+
├── become
13+
├── cache
14+
├── callback
15+
├── cliconf
16+
├── connection
17+
├── filter
18+
├── httpapi
19+
├── inventory
20+
├── lookup
21+
├── module_utils
22+
├── modules
23+
├── netconf
24+
├── shell
25+
├── strategy
26+
├── terminal
27+
├── test
28+
└── vars
29+
```
30+
31+
A full list of plugin types can be found at [Working With Plugins](https://docs.ansible.com/ansible/2.9/plugins/plugins.html).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
language: python
3+
python: "2.7"
4+
5+
# Use the new container infrastructure
6+
sudo: false
7+
8+
# Install ansible
9+
addons:
10+
apt:
11+
packages:
12+
- python-pip
13+
14+
install:
15+
# Install ansible
16+
- pip install ansible
17+
18+
# Check ansible version
19+
- ansible --version
20+
21+
# Create ansible.cfg with correct roles_path
22+
- printf '[defaults]\nroles_path=../' >ansible.cfg
23+
24+
script:
25+
# Basic role syntax check
26+
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
27+
28+
notifications:
29+
webhooks: https://galaxy.ansible.com/api/v1/notifications/

roles/synchronize_database/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Role Name
2+
=========
3+
4+
A brief description of the role goes here.
5+
6+
Requirements
7+
------------
8+
9+
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
10+
11+
Role Variables
12+
--------------
13+
14+
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
15+
16+
Dependencies
17+
------------
18+
19+
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
20+
21+
Example Playbook
22+
----------------
23+
24+
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
25+
26+
- hosts: servers
27+
roles:
28+
- { role: username.rolename, x: 42 }
29+
30+
License
31+
-------
32+
33+
BSD
34+
35+
Author Information
36+
------------------
37+
38+
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# defaults file for synchronize_database
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# handlers file for synchronize_database
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
galaxy_info:
2+
author: your name
3+
description: your role description
4+
company: your company (optional)
5+
6+
# If the issue tracker for your role is not on github, uncomment the
7+
# next line and provide a value
8+
# issue_tracker_url: http://example.com/issue/tracker
9+
10+
# Choose a valid license ID from https://spdx.org - some suggested licenses:
11+
# - BSD-3-Clause (default)
12+
# - MIT
13+
# - GPL-2.0-or-later
14+
# - GPL-3.0-only
15+
# - Apache-2.0
16+
# - CC-BY-4.0
17+
license: license (GPL-2.0-or-later, MIT, etc)
18+
19+
min_ansible_version: 2.9
20+
21+
# If this a Container Enabled role, provide the minimum Ansible Container version.
22+
# min_ansible_container_version:
23+
24+
#
25+
# Provide a list of supported platforms, and for each platform a list of versions.
26+
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
27+
# To view available platforms and versions (or releases), visit:
28+
# https://galaxy.ansible.com/api/v1/platforms/
29+
#
30+
# platforms:
31+
# - name: Fedora
32+
# versions:
33+
# - all
34+
# - 25
35+
# - name: SomePlatform
36+
# versions:
37+
# - all
38+
# - 1.0
39+
# - 7
40+
# - 99.99
41+
42+
galaxy_tags: []
43+
# List tags for your role here, one per line. A tag is a keyword that describes
44+
# and categorizes the role. Users find roles by searching for tags. Be sure to
45+
# remove the '[]' above, if you add tags to this list.
46+
#
47+
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
48+
# Maximum 20 tags per role.
49+
50+
dependencies: []
51+
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
52+
# if you add dependencies to this list.
53+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- include: synchronize_db.yml
3+
loop: "{{ postgres_databases_to_sync }}"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
- name: Create dump on database source serveur
3+
postgresql_db:
4+
name: "{{ item.src_name }}"
5+
state: dump
6+
target: "/tmp/{{ item.src_name }}.sql"
7+
target_opts: "{{ item.dump_extra_args|default('') }}"
8+
delegate_to: "{{ postgres_src_server }}"
9+
become_user: postgres
10+
11+
- name: Synchronize database
12+
synchronize:
13+
src: "/tmp/{{ item.src_name }}.sql"
14+
dest: "/tmp/{{ item.dest_name }}.sql"
15+
delegate_to: "{{ postgres_src_server }}"
16+
17+
- name: Remove existing database on target
18+
become: true
19+
become_user: postgres
20+
postgresql_db:
21+
name: "{{ item.dest_name }}"
22+
owner: "{{ item.dest_owner }}"
23+
state: absent
24+
25+
- name: Create an empty database on target
26+
become: true
27+
become_user: postgres
28+
postgresql_db:
29+
name: "{{ item.dest_name }}"
30+
owner: "{{ item.dest_owner }}"
31+
state: present
32+
33+
- name: Restore dump on database destination server
34+
postgresql_db:
35+
name: "{{ item.dest_name }}"
36+
owner: "{{ item.dest_owner }}"
37+
state: restore
38+
target: "/tmp/{{ item.dest_name }}.sql"
39+
login_host: "{{ item.dest_login_host|default(None) }}"
40+
login_user: "{{ item.dest_login_user|default(None) }}"
41+
target_opts: "{{ item.restore_extra_args|default('') }}"
42+
become_user: postgres
43+
44+
- name: Execute postscripts
45+
postgresql_query:
46+
db: "{{ item.dest_name }}"
47+
path_to_script: "{{ script }}"
48+
become_user: postgres
49+
loop: "{{ item.postscripts|default([]) }}"
50+
loop_control:
51+
loop_var: script
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
localhost
2+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- hosts: localhost
3+
remote_user: root
4+
roles:
5+
- synchronize_database
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
# vars file for synchronize_database

0 commit comments

Comments
 (0)