postgresql-service

Example:

# Install PostgreSQL database service.
- postgresql-service:
    postgresql_version: '10'
    listen_addresses:
    - '*'
    pg_hba:
    - method: md5
      address: 0.0.0.0/0

Description

This frecklet installs the PostgreSQL service using the ANXS.postgresql Ansible role.

This frecklet does not do any configuration, and uses all the defaults of the underlying Ansible role. Use other tasks to do any configuration after executing this.

Resources

Variables

Name Type Default Description

listen_addresses

list --

The network addresses this instance listens on. Default: localhost.

max_connections

integer --

Max. allowed connections. Default: 100

pg_hba

list --

A list of hosts to allow connections from, apart from the default:

local  all  postgres    trust
# "local" is for Unix domain socket connections only
local  all  all    trust
# IPv4 local connections:
host  all  all  127.0.0.1/32  trust
# IPv6 local connections:
host  all  all  ::1/128  trust
# Local root Unix user, passwordless access
local  all  postgres    peer map=root_as_postgres

port

integer --

The port this postgresql service listens on. Default: 5432.

postgresql_group_id

integer --

An (optional) custom PostgreSQL group gid.

postgresql_user_id

integer --

An (optional) custom PostgreSQL user uid.

postgresql_version

string --

The version of postgresql.

superuser_reserved_connections

integer --

Superuser reserved connections. Default: 3

Examples

Example 1

Install PostgreSQL database service.

Code
- postgresql-service:
    postgresql_version: '10'
    listen_addresses:
    - '*'
    pg_hba:
    - method: md5
      address: 0.0.0.0/0
Description

This installs the PostgreSQL database service, version 10, listening on all network interfaces, and allowing authenticated md5-connections from everywhere ('0.0.0.0/0').

Code

doc:
  short_help: Ensures PostgrSQL service is installed.
  help: |
    This frecklet installs the PostgreSQL service using the [ANXS.postgresql](https://gitlab.com/frkl-downstream/ANXS.postgresql)
    Ansible role.

    This frecklet does not do any configuration, and uses all the defaults of the underlying
    Ansible role. Use other tasks to do any configuration after executing this.

  references:
    ANXS.postgresql Ansible role: https://gitlab.com/frkl-downstream/ANXS.postgresql
  examples:
  - title: Install PostgreSQL database service.
    desc: |
      This installs the PostgreSQL database service, version 10, listening on all network interfaces, and allowing
      authenticated md5-connections from everywhere ('0.0.0.0/0').
    vars:
      postgresql_version: '10'
      listen_addresses:
      - '*'
      pg_hba:
      - method: md5
        address: 0.0.0.0/0
args:
  postgresql_version:
    doc:
      short_help: The version of postgresql.
    type: string
    empty: false
    required: false
  postgresql_group_id:
    doc:
      short_help: An (optional) custom PostgreSQL group gid.
    type: integer
    required: false
  postgresql_user_id:
    doc:
      short_help: An (optional) custom PostgreSQL user uid.
    type: integer
    required: false
  listen_addresses:
    doc:
      short_help: 'The network addresses this instance listens on. Default: localhost.'
    type: list
    schema:
      type: string
    required: false
    cli:
      param_decls:
      - --listen-address
      metavar: IP
  port:
    doc:
      short_help: 'The port this postgresql service listens on. Default: 5432.'
    type: integer
    required: false
  pg_hba:
    doc:
      short_help: A list of hosts to allow connections from.
      help: |
        A list of hosts to allow connections from, apart from the default:

        ```
        local  all  postgres    trust
        # "local" is for Unix domain socket connections only
        local  all  all    trust
        # IPv4 local connections:
        host  all  all  127.0.0.1/32  trust
        # IPv6 local connections:
        host  all  all  ::1/128  trust
        # Local root Unix user, passwordless access
        local  all  postgres    peer map=root_as_postgres
        ```
      references:
      - '[PostgreSQL pg_hba .conf documentation](https://www.postgresql.org/docs/9.1/auth-pg-hba-conf.html)'
    type: list
    required: false
    schema:
      type: dict
      schema:
        type:
          type: string
          required: true
          default: host
        database:
          type: string
          required: true
          default: all
        user:
          type: string
          required: true
          default: all
        address:
          type: string
          required: true
          default: 0.0.0.0/0
        method:
          type: string
          required: true
          allowed:
          - trust
          - reject
          - md5
          - password
          - gss
          - sspi
          - krb5
          - ident
          - peer
          - ldap
          - radius
          - cert
          - pam
    cli:
      enabled: false

  max_connections:
    doc:
      short_help: 'Max. allowed connections. Default: 100'
    type: integer
    required: false
  superuser_reserved_connections:
    doc:
      short_help: 'Superuser reserved connections. Default: 3'
    type: integer
    required: false


meta:
  tags:
  - database
  - service
  - postgresql
  - featured-frecklecutable
  - install

frecklets:
- task:
    become: true
  frecklet:
    name: group
    type: ansible-module
    skip: '{{:: postgresql_group_id | true_if_empty ::}}'
    desc:
      short: "create 'postgres' group with custom group id '{{:: postgresql_group_id\
        \ ::}}'"
    properties:
      idempotent: true
      elevated: true
      internet: false
  vars:
    name: postgres
    gid: '{{:: postgresql_group_id ::}}'
- task:
    become: true
  frecklet:
    name: user
    type: ansible-module
    skip: '{{:: postgresql_user_id | true_if_empty ::}}'
    properties:
      elevated: true
      idempotent: true
      internet: false
    desc:
      short: "create 'postgres' user with custom user id '{{:: postgresql_user_id\
        \ ::}}'"
  vars:
    name: postgres
    uid: '{{:: postgresql_user_id ::}}'
- task:
    become: true
    include-type: import
  frecklet:
    name: ANXS.postgresql
    type: ansible-role
    resources:
      ansible-role:
      - ANXS.postgresql
    desc:
      msg: setting up postgresql
      references:
        "'ANXS.postgresql' Ansible role": https://github.com/ANXS/postgresql
    properties:
      idempotent: true
      elevated: true
      internet: true
  vars:
    postgresql_version: '{{:: postgresql_version ::}}'
    postgresql_listen_addresses: '{{:: listen_addresses ::}}'
    postgresql_port: '{{:: port ::}}'
    postgresql_pg_hba_custom: '{{:: pg_hba ::}}'
    postgresql_max_connections: '{{:: max_connections ::}}'
    postgresql_superuser_reserved_connections: '{{:: superuser_reserved_connections
      ::}}'
frecklecute postgresql-service --help

Usage: frecklecute postgresql-service [OPTIONS]

  This frecklet installs the PostgreSQL service using the
  [ANXS.postgresql](https://gitlab.com/frkl-downstream/ANXS.postgresql)
  Ansible role.

  This frecklet does not do any configuration, and uses all the defaults of
  the underlying Ansible role. Use other tasks to do any configuration after
  executing this.

Options:
  --listen-address IP             The network addresses this instance listens
                                  on. Default: localhost.
  --max-connections MAX_CONNECTIONS
                                  Max. allowed connections. Default: 100
  --port PORT                     The port this postgresql service listens on.
                                  Default: 5432.
  --postgresql-group-id POSTGRESQL_GROUP_ID
                                  An (optional) custom PostgreSQL group gid.
  --postgresql-user-id POSTGRESQL_USER_ID
                                  An (optional) custom PostgreSQL user uid.
  --postgresql-version POSTGRESQL_VERSION
                                  The version of postgresql.
  --superuser-reserved-connections SUPERUSER_RESERVED_CONNECTIONS
                                  Superuser reserved connections. Default: 3
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.postgresql_service.PostgresqlService
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class PostgresqlService(AutoPycklet):
    """This frecklet installs the PostgreSQL service using the [ANXS.postgresql](https://gitlab.com/frkl-downstream/ANXS.postgresql)
     Ansible role.

     This frecklet does not do any configuration, and uses all the defaults of the underlying
     Ansible role. Use other tasks to do any configuration after executing this.

       Args:
         listen_addresses: The network addresses this instance listens on. Default: localhost.
         max_connections: Max. allowed connections. Default: 100
         pg_hba: A list of hosts to allow connections from.
         port: The port this postgresql service listens on. Default: 5432.
         postgresql_group_id: An (optional) custom PostgreSQL group gid.
         postgresql_user_id: An (optional) custom PostgreSQL user uid.
         postgresql_version: The version of postgresql.
         superuser_reserved_connections: Superuser reserved connections. Default: 3

    """

    FRECKLET_ID = "postgresql-service"

    listen_addresses: List = None
    max_connections: int = None
    pg_hba: List = None
    port: int = None
    postgresql_group_id: int = None
    postgresql_user_id: int = None
    postgresql_version: str = None
    superuser_reserved_connections: int = None


    def __post_init__(self):
        super(PostgresqlService, self).__init__(var_names=["listen_addresses", "max_connections", "pg_hba", "port", "postgresql_group_id", "postgresql_user_id", "postgresql_version", "superuser_reserved_connections"])


frecklet_class = PostgresqlService
# -*- coding: utf-8 -*-


#
# module path: pycklets.postgresql_service.PostgresqlService
#


from pyckles import AutoPycklet

class PostgresqlService(AutoPycklet):
    """This frecklet installs the PostgreSQL service using the [ANXS.postgresql](https://gitlab.com/frkl-downstream/ANXS.postgresql)
     Ansible role.

     This frecklet does not do any configuration, and uses all the defaults of the underlying
     Ansible role. Use other tasks to do any configuration after executing this.

       Args:
         listen_addresses: The network addresses this instance listens on. Default: localhost.
         max_connections: Max. allowed connections. Default: 100
         pg_hba: A list of hosts to allow connections from.
         port: The port this postgresql service listens on. Default: 5432.
         postgresql_group_id: An (optional) custom PostgreSQL group gid.
         postgresql_user_id: An (optional) custom PostgreSQL user uid.
         postgresql_version: The version of postgresql.
         superuser_reserved_connections: Superuser reserved connections. Default: 3

    """

    FRECKLET_ID = "postgresql-service"

    def __init__(self, listen_addresses=None, max_connections=None, pg_hba=None, port=None, postgresql_group_id=None, postgresql_user_id=None, postgresql_version=None, superuser_reserved_connections=None):

        super(PostgresqlService, self).__init__(var_names=["listen_addresses", "max_connections", "pg_hba", "port", "postgresql_group_id", "postgresql_user_id", "postgresql_version", "superuser_reserved_connections"])
        self._listen_addresses = listen_addresses
        self._max_connections = max_connections
        self._pg_hba = pg_hba
        self._port = port
        self._postgresql_group_id = postgresql_group_id
        self._postgresql_user_id = postgresql_user_id
        self._postgresql_version = postgresql_version
        self._superuser_reserved_connections = superuser_reserved_connections

    @property
    def listen_addresses(self):
        return self._listen_addresses

    @listen_addresses.setter
    def listen_addresses(self, listen_addresses):
        self._listen_addresses = listen_addresses

    @property
    def max_connections(self):
        return self._max_connections

    @max_connections.setter
    def max_connections(self, max_connections):
        self._max_connections = max_connections

    @property
    def pg_hba(self):
        return self._pg_hba

    @pg_hba.setter
    def pg_hba(self, pg_hba):
        self._pg_hba = pg_hba

    @property
    def port(self):
        return self._port

    @port.setter
    def port(self, port):
        self._port = port

    @property
    def postgresql_group_id(self):
        return self._postgresql_group_id

    @postgresql_group_id.setter
    def postgresql_group_id(self, postgresql_group_id):
        self._postgresql_group_id = postgresql_group_id

    @property
    def postgresql_user_id(self):
        return self._postgresql_user_id

    @postgresql_user_id.setter
    def postgresql_user_id(self, postgresql_user_id):
        self._postgresql_user_id = postgresql_user_id

    @property
    def postgresql_version(self):
        return self._postgresql_version

    @postgresql_version.setter
    def postgresql_version(self, postgresql_version):
        self._postgresql_version = postgresql_version

    @property
    def superuser_reserved_connections(self):
        return self._superuser_reserved_connections

    @superuser_reserved_connections.setter
    def superuser_reserved_connections(self, superuser_reserved_connections):
        self._superuser_reserved_connections = superuser_reserved_connections



frecklet_class = PostgresqlService