enix.postgresql

enix.postgresql

用于在 UNIX 主机上通过 Ansible 部署和配置 postgresql 上游版本的角色。

要求

支持的目标操作系统:

  • Debian 9 "Stretch"
  • Debian 10 "Buster"
  • Debian 11 "Bullseye"
  • Ubuntu 20.04 "Focal"
  • Ubuntu 22.04 "Jammy"

角色变量

这个角色预加载了几乎所有可用的默认配置。您可以在主机/组变量、库存中或在 play 中覆盖每一个。有关配置的详细信息,请参见 defaults/main.yml 中的注释默认值。

  • postgresql__version - 要安装的 postgresql 版本,默认是 14。可选版本:10, 11, 12, 13, 14。
  • postgresql__extensions - 要安装的 postgresql 扩展包。
  • postgresql__global_config_options - 要设置到 postgresql.conf 的全局配置选项。常见选项包括:
postgresql__global_config_options:
  - option: listen_addresses
    value: '*'
  - option: log_min_duration_statement
    value: 1000
  - option: bonjour
    value: off
    state: absent
  • postgresql__includeconf - 要模板化并推送到 conf.d/ 中的配置文件列表。
  • postgresql__hba_entries - 配置的基于主机的身份验证条目。将覆盖 PostgreSQL 默认设置。默认值未定义。必需字段有 type, database, user, auth_method,可选字段有 address, ip_address, ip_mask, auth_options。要复制包提供的配置:
postgresql_hba_entries:
  - {type: local, database: all, user: postgres, auth_method: peer}
  - {type: local, database: all, user: all, auth_method: peer}
  - {type: host, database: all, user: all, address: '127.0.0.1/32', auth_method: md5}
  - {type: host, database: all, user: all, address: '::1/128', auth_method: md5}
# 从版本 10 开始有复制角色
  - {type: local, database: replication, user: all, auth_method: peer}
  - {type: host, database: replication, user: all, address: '127.0.0.1/32', auth_method: md5}
  - {type: host, database: replication, user: all, address: '::1/128', auth_method: md5}
  • postgresql__users - 要在 postgresql 服务器上创建的用户及其凭据:
postgresql__users:
  - {name: "foobar",
    password: "supersecure",
    encrypted: yes,
    expires: 'infinity',
    state: 'present',
    conn_limit: none,
    priv: none,
    role_attr_flags: none,
    db: none
  • postgresql__databases - 要安装在服务器上的数据库状态。唯一必需的参数是名称:
postgresql__databases:
  - {name: test,
    lc_collate: 'en_US.UTF-8',
    lc_ctype: 'en_US.UTF-8',
    encoding: 'UTF-8',
    template: 'template0',
    owner: postgres,
    extension: [], # 请确保在此之前已安装所需的扩展模块
    state: 'present'
   }
  • postgresql__install_pgbackrest - 安装 pgbackrest 软件 https://pgbackrest.org
  • postgresql__install_pg_auto_failover - 安装 pg_auto_failover 软件 https://github.com/citusdata/pg_auto_failover
  • postgresql__disable_initdb - 禁用默认主集群的创建。这在创建 pg_auto_failover 集群或仅安装软件包时很有用。

依赖关系

使用方法

使用 Ansible galaxy 的 requirements.yml:

    - src: enix.postgresql

然后将其添加到您的 play 的角色中:

    - hosts: all
      roles:
        - role enix.postgresql:
            postgresql__var: true

您也可以将该角色作为 playbook 使用。系统将提示您选择要配置的主机,您可以使用 --extra-vars 进一步配置 play。

ansible-playbook -i inventory --extra-vars='{...}' main.yml

待办事项

  • 检查是否在副本上进行部署。在这种情况下,不要创建数据库和用户。
  • 使用 molecule 添加 CI 测试。

更新日志

2.1.0

添加 pgbackrest 和 pg_auto_failover 软件的安装。 添加 disable_initdb 选项。这禁止安装设置默认的主 postgresql 集群数据库。

2.0.0

添加对 postgresql 13 和 14 的支持。 添加对 Debian 10 Buster 和 Debian 11 Bullseye 的支持。 添加对 Ubuntu 20.04 Focal 和 Ubuntu 22.04 Jammy 的支持。 删除对 Debian Jessie 的支持。 切换到 molecule 测试。 使用新的 ansible FQDN 任务。

1.2.0

添加对 postgresql 12 的支持。

1.1.0

在数据库定义和配置中添加扩展列表的支持。

1.0.0

初始版本。

许可证

GPLv2

作者信息

Laurent CORBES laurent.corbes@enix.fr - http://www.enix.io

关于项目

Ansible role to deploy postgresql software

安装
ansible-galaxy install enix.postgresql
许可证
Unknown
下载
19.2k
拥有者
Enix