Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1 from FLiPp3r90/dev
Browse files Browse the repository at this point in the history
Minor changes, bugfixes. Add some CI tests with molecule. Fix linting errors.
  • Loading branch information
FLiPp3r90 authored Mar 5, 2021
2 parents ddf151d + acbc6f5 commit 3435428
Show file tree
Hide file tree
Showing 28 changed files with 305 additions and 179 deletions.
3 changes: 3 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
skip_list:
- 'yaml'
- 'role-name'
49 changes: 49 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---

# Configuration for probot-stale - https://github.com/probot/stale

# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale: 90

# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose: 30

# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
onlyLabels: []

# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
exemptLabels:
- pinned
- security
- planned

# Set to true to ignore issues in a project (defaults to false)
exemptProjects: false

# Set to true to ignore issues in a milestone (defaults to false)
exemptMilestones: false

# Set to true to ignore issues with an assignee (defaults to false)
exemptAssignees: false

# Label to use when marking as stale
staleLabel: stale

# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun: 30

pulls:
markComment: |-
This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution!
unmarkComment: >-
This pull request is no longer marked for closure.
closeComment: >-
This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details.
issues:
markComment: |-
This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!
unmarkComment: >-
This issue is no longer marked for closure.
closeComment: >-
This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.
65 changes: 65 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: CI
'on':
pull_request:
push:
branches:
- master
schedule:
- cron: "0 3 * * 5"

defaults:
run:
working-directory: 'FLiPp3r90.repmgr'

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v2
with:
path: 'FLiPp3r90.repmgr'

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install yamllint ansible ansible-lint

- name: Lint code.
run: |
yamllint .
ansible-lint
molecule:
name: Molecule
runs-on: ubuntu-latest
strategy:
matrix:
distro:
- centos7

steps:
- name: Check out the codebase.
uses: actions/checkout@v2
with:
path: 'FLiPp3r90.repmgr'

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install ansible molecule[docker] docker

- name: Run Molecule tests.
run: molecule test
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.retry
*/__pycache__
*.pyc
.cache
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
extends: default

rules:
line-length:
max: 180
level: warning

ignore: |
.github/stale.yml
Empty file modified LICENSE
100644 → 100755
Empty file.
57 changes: 25 additions & 32 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
ansible-repmgr
======
# Ansible Role: Repmgr

This role installs and configures repmgr for Postgresql replication
[![CI](https://github.com/FLiPp3r90/ansible-role-repmgr/workflows/CI/badge.svg?event=push)](https://github.com/FLiPp3r90/ansible-role-repmgr/actions?query=workflow%3ACI)

Requirements
------------
This role installs and configures repmgr for Postgresql replication

Assumes PostgreSQL is already installed and running.
## Requirements
You need a PostgreSQL installation to use this role.
But before you can deploy the whole role, you need to install repmgr first because you need the repmgr binaries when before starting the Postgresql database with repmgr shared preload libraries.

Role Variables
--------------
## Role Variables

See defaults/main.yml

Dependencies
------------
* Repmgr 5.x
* Postgres >= 9.6
* Ansible ANXS/postgresql
## Dependencies

None.

Usage
-----
## Usage

In the playbook for the master:

```yaml
- hosts: db
roles:
- ansible-repmgr
- FLiPp3r90/repmgr
vars:
repmgr_install_only: True
repmgr_install_only: true

- hosts: db
roles:
- role: anxs/postgresql
- role: ansible-repmgr
- role: FLiPp3r90/repmgr
vars:
repmgr_is_master: True
repmgr_is_master: true
repmgr_node_id: 1
```
Expand All @@ -46,30 +41,30 @@ In the playbook for the slave:
```yaml
- hosts: db
roles:
- ansible-repmgr
- FLiPp3r90/repmgr
vars:
repmgr_install_only: True
repmgr_install_only: true

- hosts: db
roles:
- role: anxs/postgresql
- role: ansible-repmgr
- role: FLiPp3r90/repmgr
vars:
repmgr_node_id: 2
repmgr_clone_standby: True
repmgr_register_standby: True
repmgr_clone_standby: true
repmgr_register_standby: true
```
### Tricks and Tips
## Tricks and Tips
You will need to create a `repmgr` user on your master database with
appropriate permissions. This two things.

1. Create a database use `repmgr` with the permissions
`SUPERUSER,REPLICATION,LOGIN`
2. Add an entry to the `pg_hba.conf` file giving explicit access to the
replication database to both the `repmgr` and the `postgres` users
s replication database to both the `repmgr` and the `postgres` users

```bash
# pg_hba.conf
Expand All @@ -87,12 +82,10 @@ If you have stricted sshd access configured on your database hosts you have to e
You have to set sudo rules that grants postgresql user to start/stop/restart postgresql database.


License
-------
## License

Apache-2.0
MIT

Author Information
------------------
## Author Information

Filip Krahl
[FLiPp3r90](https://github.com/FLiPp3r90)
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'github_changelog_generator/task'

GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.user = 'FLiPp3r90'
config.project = 'ansible-role-repmgr'
config.since_tag = '1.3'
config.future_release = '0.1.0'
end
61 changes: 18 additions & 43 deletions defaults/main.yml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
---
# versions
postgres_release: 12
repmgr_release: 5

# packages
# os user
postgres_user: postgres
postgres_group: postgres


# packages
repmgr_package: "repmgr{{ postgres_release }}"
postgres_package: "postgresql{{ postgres_release }}"
postgresql_server_package: "postgresql{{ postgres_release }}-server"

# services
repmgr_service: "repmgr{{postgres_release}}"
Expand All @@ -22,42 +25,13 @@ postgres_ssh_rsa_key: "{{ postgres_ssh_dir }}/id_rsa"
postgres_data_directory: "/var/lib/pgsql/{{ postgres_release }}/data"
postgres_conf_directory: "/etc/postgresql/{{ postgres_release }}/data"

# repository
repmgr_install_repository: True
repmgr_install_gpg_key: True
# repmgr repository
repmgr_install_repository: true
repmgr_repository: "https://dl.2ndquadrant.com/default/release/browse/rpm/packages/rhel/{{ ansible_distribution_major_version }}/{{ ansible_architecture }}/{{ postgres_release }}"
repmgr_gpg_file: '/etc/pki/rpm-gpg/RPM-GPG-KEY-2NDQ-DL-DEFAULT'
repmgr_gpg_key: '-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1
mQINBFqpNU0BEAC6tFZf3Vt5FB4sG0pDeomVypnxTudww/bFm4ZWg3NsP4tnhaao
ngO32/ExyyhLbYSIVsQIHYPEamzLJbJwCDTxMLE2x7NrXbC0xeel0Ku7YQcL5VZC
EWNJapAIgynao5nTlPMxV4U5TT2BWT2FlbyyRUCn9ng6VvTuxMczF9yKtP4ITKwy
DWe4EGJmxumFyiMzjH3QN96PT+kUfPgDbf6oQfCCZAauVzTpXmkWpt1bw5BlDpXF
gEx7bLYufaHobVmchrsE+fNGRTvByeWp5sXE+YCeOJWFwL5chSRSP/M5xMFR3C8C
k6OVT0z2h7a/8ftZMIa3L5Fuc6oQxPY3XZe0JP4jOfqhBw0I2IEffW9yEKqh6GkS
VK1JaDFnS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WSu9Ha/w79loFpfN
RYH5/+4dehDUjcrluUcN7hshJijqlkgUctjLYOdleJHKAgSX06+6oeu74SH/i+z6
6SUYZxf80izYErwrFxhxlx8=
=V6ND
-----END PGP PUBLIC KEY BLOCK-----'

# postgresql repository
postgres_repo_name: "postgres_{{ postgres_release }}"
postgres_repo: "https://download.postgresql.org/pub/repos/yum/{{ postgres_release }}/redhat/rhel-{{ ansible_distribution_major_version }}-{{ ansible_architecture }}"

# repmgr vars
repmgr_conf_file: 'repmgr.conf'
Expand All @@ -83,9 +57,10 @@ repmgr_restart_command: "/usr/bin/sudo /usr/bin/systemctl restart postgresql-{{


# role management
repmgr_is_master: False
repmgr_register_master: True
repmgr_register_standby: False
repmgr_clone_standby: False
repmgr_bootstrap: True
repmgr_install_only: False
repmgr_is_master: false
repmgr_register_master: false
repmgr_register_standby: false
repmgr_clone_standby: false
repmgr_bootstrap: false
repmgr_install_only: true
repmgr_install_postgresql: false
1 change: 0 additions & 1 deletion handlers/main.yml
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@
service:
name: "{{ postgres_service }}"
state: started

Loading

0 comments on commit 3435428

Please sign in to comment.