geerlingguy.postgresql

Ansible角色:PostgreSQL

CI

在RHEL/CentOS或Debian/Ubuntu服务器上安装和配置PostgreSQL服务器。

要求

没有特殊要求;请注意,此角色需要root访问权限,因此需要在包含全局become: yes的剧本中运行,或像这样在剧本中调用该角色:

- hosts: database
  roles:
    - role: geerlingguy.postgresql
      become: yes

角色变量

可用的变量如下所示,并附有默认值(请参见defaults/main.yml):

postgresql_enablerepo: ""

(仅适用于RHEL/CentOS)您可以通过在此处传递一个repo来设置用于PostgreSQL安装的源。

postgresql_restarted_state: "restarted"

配置更改时设置服务的状态。推荐的值是restartedreloaded

postgresql_python_library: python-psycopg2

Ansible用于与PostgreSQL通信的库。如果您使用Python 3(例如通过ansible_python_interpreter设置),则应将其更改为python3-psycopg2

postgresql_user: postgres
postgresql_group: postgres

PostgreSQL运行的用户和组。

postgresql_unix_socket_directories:
  - /var/run/postgresql

PostgreSQL的套接字将创建的目录(通常是一个,也可以是多个)。

postgresql_service_state: started
postgresql_service_enabled: true

控制postgreSQL服务的状态以及是否在启动时启动。

postgresql_global_config_options:
  - option: unix_socket_directories
    value: '{{ postgresql_unix_socket_directories | join(",") }}'
  - option: log_directory
    value: 'log'

将设置在postgresql.conf中的全局配置选项。 对于9.3版本之前的PostgreSQL,您至少需要重写此变量并将option设置为unix_socket_directory。 如果您使用其他路径覆盖option: log_directory的值,则该角色将为您创建该路径。

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 }

配置基于主机的身份验证条目,将设置在pg_hba.conf中。条目的选项包括:

  • type(必需)
  • database(必需)
  • user(必需)
  • address(此项或以下两项之一是必需的)
  • ip_address
  • ip_mask
  • auth_method(必需)
  • auth_options(可选)

如果要重写,请确保复制defaults/main.yml中的所有现有条目,以便保留现有条目。

postgresql_locales:
  - 'en_US.UTF-8'

(仅适用于Debian/Ubuntu)用于生成PostgreSQL数据库使用的语言环境。

postgresql_databases:
  - name: exampledb # 必需;其余的可选
    lc_collate: # 默认为'en_US.UTF-8'
    lc_ctype: # 默认为'en_US.UTF-8'
    encoding: # 默认为'UTF-8'
    template: # 默认为'template0'
    login_host: # 默认为'localhost'
    login_password: # 默认为未设置
    login_user: # 默认为'postgresql_user'
    login_unix_socket: # 默认为postgresql_unix_socket_directories中的第一个
    port: # 默认为未设置
    owner: # 默认为postgresql_user
    state: # 默认为'present'

确保服务器上存在的数据库列表。只有name是必需的;所有其他属性都是可选的。

postgresql_users:
  - name: jdoe #必需;其余的可选
    password: # 默认为未设置
    encrypted: # 默认为未设置
    priv: # 默认为未设置
    role_attr_flags: # 默认为未设置
    db: # 默认为未设置
    login_host: # 默认为'localhost'
    login_password: # 默认为未设置
    login_user: # 默认为'{{ postgresql_user }}'
    login_unix_socket: # 默认为postgresql_unix_socket_directories中的第一个
    port: # 默认为未设置
    state: # 默认为'present'

确保服务器上存在的用户列表。只有name是必需的;所有其他属性都是可选的。

postgres_users_no_log: true

在管理用户时是否输出用户数据(可能包含敏感信息,如密码)。

postgresql_version: [特定于操作系统]
postgresql_data_dir: [特定于操作系统]
postgresql_bin_path: [特定于操作系统]
postgresql_config_path: [特定于操作系统]
postgresql_daemon: [特定于操作系统]
postgresql_packages: [特定于操作系统]

通过该角色的vars目录中的包含文件设置的特定于操作系统的变量。除非您使用的是未通过系统包安装的PostgreSQL版本,否则不应覆盖这些变量。

依赖

无。

示例剧本

- hosts: database
  become: yes
  vars_files:
    - vars/main.yml
  roles:
    - geerlingguy.postgresql

vars/main.yml

postgresql_databases:
  - name: example_db
postgresql_users:
  - name: example_user
    password: supersecure

许可

MIT / BSD

作者信息

该角色由Jeff Geerling于2016年创建,他是Ansible for DevOps的作者。

关于项目

PostgreSQL server for Linux.

安装
ansible-galaxy install geerlingguy.postgresql
许可证
mit
下载
3.3M
拥有者
Father, author, developer, maker. Sometimes called "an inflammatory enigma". #stl #drupal #ansible #k8s #raspberrypi #crohns