mahdi22.postgresql

Ansible 角色 postgresql

这是一个用于在 RHEL/CentOS、Debian、Ubuntu 和 SUSE SLES 发行版的 Linux 上安装 PostgreSQL 的 Ansible 角色。该角色的具体职责包括:

  • 安装 PostgreSQL
  • 配置 PostgreSQL 参数和认证
  • 创建用户
  • 创建数据库

安装

$ ansible-galaxy install mahdi22.postgresql

角色变量

variable/main.yml 设置 PostgreSQL 配置参数或使用默认值

postgresql_config:
  - option: port
    value: 5432
  - option: log_destination
    value: syslog
  - option: log_directory
    value: /var/log/postgresql/

设置或修改 PostgreSQL 认证参数或使用默认值

postgresql_authentication:
  - {type: local, database: all, user: postgres, auth_method: peer}
  - {type: local, database: all, user: all, auth_method: md5}
  - {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}
  - {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 数据库和用户,如果在 default/main.yml 中未设置 create_users: no 和 create_databases: no

创建多个数据库和用户的示例:

postgresql_databases_users: []
#postgresql_databases_users:
#  - {database: test, user: user1, userpassword: user1pass, priv: ALL}  #添加数据库 'test' 和用户 'user1',密码为 'user1pass',权限为 'ALL'
#  - {database: test1, user:'', userpassword: '', priv: ''}              #仅添加数据库 'test1'
#  - {database: '', user: user2, userpassword: user2pass, priv: ''}      #仅添加用户 'user2',密码为 'user2pass'
  • 要仅创建数据库而不创建用户,设置 database: databasename, user:''
  • 要仅创建用户,设置 database: '', user: username, userpassword: password
  • 要创建带有用户权限的数据库,设置 database: databasename, user: username, userpassword: password, priv: privileges

基本配置

变量 默认值 注释
use_proxy 'False' 如果受管主机在网络代理后面,设置 use_proxy: True
http_proxy 'http://proxy.lab.local:8080/' 设置代理服务器和端口,替换 proxy.lab.local:8080
https_proxy 'http://proxy.lab.local:8080/' 设置代理服务器和端口,替换 proxy.lab.local:8080
postgresql_version 将安装的 PostgreSQL 版本
listen_addresses_host_ip yes 是,启用 PostgreSQL 在网络 IP 接口上监听
create_users yes 创建配置在变量文件中的 PostgreSQL 用户
create_databases yes 创建配置在变量文件中的 PostgreSQL 数据库

备注

(1) 如果受管主机在网络代理后面,请在 defaults/main.yml 文件中设置以下变量:

use_proxy: False
proxy_env:
  http_proxy: http://proxy.local:8080/
  https_proxy: http://proxy.local:8080/

示例剧本

- hosts: dbservers
  roles:
    - role: mahdi22.postgresql
      become: yes

测试

该角色在以下 Linux 发行版上进行了测试:

  • RHEL/CentOS 8 PostgreSQL 版本 (9.5, 9.4, 10, 11, 12, 13)
  • RHEL/CentOS 7 PostgreSQL 版本 (9.5, 9.4, 10, 11, 12, 13)
  • Debian 10 PostgreSQL 版本 (9.5, 9.4, 10, 11, 12, 13)
  • Debian 9 PostgreSQL 版本 (9.5, 9.4, 10, 11, 12, 13)
  • Ubuntu 20.04 PostgreSQL 版本 (9.5, 9.4, 10, 11, 12, 13)
  • Ubuntu 18.04 PostgreSQL 版本 (9.5, 9.4, 10, 11, 12, 13)
  • Ubuntu 16.04 PostgreSQL 版本 (9.5, 9.4, 10, 11, 12, 13)
  • Suse SLES 12 PostgreSQL 版本 (9.5, 9.4, 10, 11, 12)
  • Suse SLES 15 PostgreSQL 版本 (11, 12, 13)
关于项目

Install and configure Postgresql server on Rhel/CentOS, Debian, Ubuntu and SUSE SLES ditributions

安装
ansible-galaxy install mahdi22.postgresql
许可证
Unknown
下载
95
拥有者