diff --git a/defaults/main.yml b/defaults/main.yml index 444acf3..aad97d2 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -4,3 +4,19 @@ postgres_version: 10 postgres_repository_filename: "Postgresql-{{ postgres_version | regex_replace('\\.') }}" postgres_user: postgres postgres_group: postgres + +# available postgresql.conf options +postgres_log_destination: + - stderr +postgres_log_dirname: log +postgres_log_filename: postgresql.log +postgres_log_rotation_age: 1d +postgres_log_rotation_size: 0 + +postgres_connection_port: 5432 +postgres_connection_addresses: + - localhost +postgres_socket_directories: + - /var/run/postgresql + +postgres_password_encryption: md5 diff --git a/tasks/config.yml b/tasks/config.yml new file mode 100644 index 0000000..d45b66a --- /dev/null +++ b/tasks/config.yml @@ -0,0 +1,10 @@ +--- +- block: + - name: Setup global config file + template: + src: postgresql/data/postgresql.conf.j2 + dest: "{{ __postgres_config_path }}/postgresql.conf" + mode: 0600 + notify: __postgres_restart + become: True + become_user: root diff --git a/tasks/main.yml b/tasks/main.yml index f02fa9a..57b44a9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,4 +1,5 @@ --- - import_tasks: prepare.yml - import_tasks: install.yml +- import_tasks: config.yml - import_tasks: post_tasks.yml diff --git a/templates/postgresql/data/postgresql.conf.j2 b/templates/postgresql/data/postgresql.conf.j2 new file mode 100644 index 0000000..6a1c281 --- /dev/null +++ b/templates/postgresql/data/postgresql.conf.j2 @@ -0,0 +1,283 @@ +{{ ansible_managed }} +# ----------------------------- +# PostgreSQL configuration file +# ----------------------------- +# +# This file consists of lines of the form: +# +# name = value +# +# (The "=" is optional.) Whitespace may be used. Comments are introduced with +# "#" anywhere on a line. The complete list of parameter names and allowed +# values can be found in the PostgreSQL documentation. + + +#------------------------------------------------------------------------------ +# FILE LOCATIONS +#------------------------------------------------------------------------------ + +# The default values of these variables are driven from the -D command-line +# option or PGDATA environment variable, represented here as ConfigDir. + + +#------------------------------------------------------------------------------ +# CONNECTIONS AND AUTHENTICATION +#------------------------------------------------------------------------------ + +# - Connection Settings - + +listen_addresses = '{{ postgres_connection_addresses | join(",") }}' +port = {{ postgres_connection_port }} +max_connections = 100 +#superuser_reserved_connections = 3 +unix_socket_directories = '{{ postgres_socket_directories }}' +#unix_socket_group = '{{ postgres_socket_directories | join(",") }}' +#unix_socket_permissions = 0777 +#bonjour = off +#bonjour_name = '' + +# - Security and Authentication - + +#authentication_timeout = 1min +#ssl = off +#ssl_ciphers = 'HIGH:MEDIUM:+3DES:!aNULL' +#ssl_prefer_server_ciphers = on +#ssl_ecdh_curve = 'prime256v1' +#ssl_dh_params_file = '' +#ssl_cert_file = 'server.crt' +#ssl_key_file = 'server.key' +#ssl_ca_file = '' +#ssl_crl_file = '' +password_encryption = {{ postgres_password_encryption }} +#db_user_namespace = off +#row_security = on + +# GSSAPI using Kerberos +#krb_server_keyfile = '' +#krb_caseins_users = off + +# - TCP Keepalives - +# see "man 7 tcp" for details + +#tcp_keepalives_idle = 0 +#tcp_keepalives_interval = 0 +#tcp_keepalives_count = 0 + + +#------------------------------------------------------------------------------ +# RESOURCE USAGE (except WAL) +#------------------------------------------------------------------------------ +shared_buffers = 128MB +dynamic_shared_memory_type = posix + +# - Disk - + +# - Kernel Resource Usage - + +# - Cost-Based Vacuum Delay - + +# - Background Writer - + +# - Asynchronous Behavior - + + +#------------------------------------------------------------------------------ +# WRITE AHEAD LOG +#------------------------------------------------------------------------------ + +# - Settings - + +# - Checkpoints - + +# - Archiving - + + +#------------------------------------------------------------------------------ +# REPLICATION +#------------------------------------------------------------------------------ + +# - Sending Server(s) - + +# Set these on the master and on any standby that will send replication data. + +# - Master Server - + +# These settings are ignored on a standby server. + +# - Standby Servers - + +# These settings are ignored on a master server. + +# - Subscribers - + +# These settings are ignored on a publisher. + + +#------------------------------------------------------------------------------ +# QUERY TUNING +#------------------------------------------------------------------------------ + +# - Planner Method Configuration - + +# - Planner Cost Constants - + +# - Genetic Query Optimizer - + +# - Other Planner Options - + + +#------------------------------------------------------------------------------ +# ERROR REPORTING AND LOGGING +#------------------------------------------------------------------------------ + +# - Where to Log - + +log_destination = '{{ postgres_log_destination | join(",") }}' +# This is used when logging to stderr: +{% if "stderr" in postgres_log_destination or "csvlog" in postgres_log_destination %} +logging_collector = on +{% else %} +logging_collector = off +{% endif %} +# These are only used if logging_collector is on: +log_directory = '{{ postgres_log_directory }}' +log_filename = '{{ postgres_log_filename }}' +#log_file_mode = 0600 +log_truncate_on_rotation = on +log_rotation_age = {{ postgres_log_rotation_age }} +log_rotation_size = {{ postgres_log_rotation_size }} + + +# These are relevant when logging to syslog: +#syslog_facility = 'LOCAL0' +#syslog_ident = 'postgres' +#syslog_sequence_numbers = on +#syslog_split_messages = on + +# - When to Log - +#client_min_messages = notice +#log_min_messages = warning +#log_min_error_statement = error +#log_min_duration_statement = -1 + +# - What to Log - +#debug_print_parse = off +#debug_print_rewritten = off +#debug_print_plan = off +#debug_pretty_print = on +#log_checkpoints = off +#log_connections = off +#log_disconnections = off +#log_duration = off +#log_error_verbosity = default # terse, default, or verbose messages +#log_hostname = off +log_line_prefix = '%m [%p] ' +#log_lock_waits = off +#log_statement = 'none' +#log_replication_commands = off +#log_temp_files = -1 +log_timezone = 'Europe/Berlin' + + +# - Process Title - + +#cluster_name = '' +#update_process_title = on + + +#------------------------------------------------------------------------------ +# RUNTIME STATISTICS +#------------------------------------------------------------------------------ + +# - Query/Index Statistics Collector - + +# - Statistics Monitoring - + + +#------------------------------------------------------------------------------ +# AUTOVACUUM PARAMETERS +#------------------------------------------------------------------------------ + + +#------------------------------------------------------------------------------ +# CLIENT CONNECTION DEFAULTS +#------------------------------------------------------------------------------ + +# - Statement Behavior - + +# - Locale and Formatting - + +datestyle = 'iso, mdy' +#intervalstyle = 'postgres' +timezone = 'Europe/Berlin' +#timezone_abbreviations = 'Default' +#extra_float_digits = 0 +#client_encoding = sql_ascii + +# These settings are initialized by initdb, but they can be changed. +lc_messages = 'en_US.UTF-8' +lc_monetary = 'en_US.UTF-8' +lc_numeric = 'en_US.UTF-8' +lc_time = 'en_US.UTF-8' + +# default configuration for text search +default_text_search_config = 'pg_catalog.english' + +# - Other Defaults - + +#dynamic_library_path = '$libdir' +#local_preload_libraries = '' +#session_preload_libraries = '' + + +#------------------------------------------------------------------------------ +# LOCK MANAGEMENT +#------------------------------------------------------------------------------ + + +#------------------------------------------------------------------------------ +# VERSION/PLATFORM COMPATIBILITY +#------------------------------------------------------------------------------ + +# - Previous PostgreSQL Versions - + +#array_nulls = on +#backslash_quote = safe_encoding +#default_with_oids = off +#escape_string_warning = on +#lo_compat_privileges = off +#operator_precedence_warning = off +#quote_all_identifiers = off +#standard_conforming_strings = on +#synchronize_seqscans = on + +# - Other Platforms and Clients - + +#transform_null_equals = off + + +#------------------------------------------------------------------------------ +# ERROR HANDLING +#------------------------------------------------------------------------------ + +#exit_on_error = off # terminate session on any error? +#restart_after_crash = on # reinitialize after backend crash? + + +#------------------------------------------------------------------------------ +# CONFIG FILE INCLUDES +#------------------------------------------------------------------------------ + +# These options allow settings to be loaded from files other than the +# default postgresql.conf. + +#include_dir = 'conf.d' +#include_if_exists = 'exists.conf' +#include = 'special.conf' + + +#------------------------------------------------------------------------------ +# CUSTOMIZED OPTIONS +#------------------------------------------------------------------------------ + +# Add settings for extensions here diff --git a/vars/main.yml b/vars/main.yml index 19db9ee..200ee7a 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -7,4 +7,4 @@ __postgres_packages: - "{{ __postgres_packagename }}" - "{{ __postgres_packagename }}-server" __postgres_data_dir: "/var/lib/pgsql/{{ __postgres_version }}/data" -__postgres_config_path: "/var/lib/pgsql/data" +__postgres_config_path: "{{ __postgres_data_dir }}"