geerlingguy / ansible-role-postgresql

Ansible Role - PostgreSQL
https://galaxy.ansible.com/geerlingguy/postgresql/
MIT License
565 stars 385 forks source link

Unable to define global config with version 3.4.0 #217

Closed fblackburn1 closed 9 months ago

fblackburn1 commented 2 years ago

Given I use the latest ansible-role-postgres (3.4.0) Given I override postgresql_global_config_options variable (but not log_directory option) When I execute my playbook Then I get the following error:

TASK [geerlingguy.postgresql : Define postgresql_log_dir.] ************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'log_directory'\n\nThe error appears to be in '/root/.ansible
/roles/geerlingguy.postgresql/tasks/variables.yml': line 58, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Define po
stgresql_log_dir.\n  ^ here\n"}

Workaround: define log_directory inside my custom postgresql_global_config_options variable Expected: No need to define log_directory option

Playbook:

- name: Postgres issue
  hosts: test
  - name: Install postgres
    include_role:
      name: geerlingguy.postgresql
    vars:
      postgresql_global_config_options:
        - option: listen_addresses
          value: "{{ postgresql_listen_addresses | default('127.0.0.1') }}"
dcardellino commented 2 years ago

Same issue here.

Using Version 3.3.1 helps!

Raptus1 commented 2 years ago

Same as @dcardellino here.

Update: In my case it was because the variable postgresql_global_config_options got facts set in another role, overwriting the variable set in this role.

https://github.com/pulp/pulp_installer/issues/1242#issuecomment-1182983131

hackingguy commented 2 years ago
---
- hosts: db
  become: yes
  pre_tasks:
    - name: Update repositories cache
      apt:
        update_cache: yes
  roles:
    - role: geerlingguy.postgresql
      vars:
        postgresql_users:
          - name: vagrant
            password: vagrant
        postgresql_databases:
          - name: books
            owner: vagrant
        postgresql_hba_entries:
          - { type: host, database: all, user: all, address: '0.0.0.0/0', auth_method: md5 }
        postgresql_global_config_options:
          - option: listen_addresses
            value: '*'
image
stale[bot] commented 1 year ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

ghost commented 1 year ago
---
- hosts: db
  become: yes
  pre_tasks:
    - name: Update repositories cache
      apt:
        update_cache: yes
  roles:
    - role: geerlingguy.postgresql
      vars:
        postgresql_users:
          - name: vagrant
            password: vagrant
        postgresql_databases:
          - name: books
            owner: vagrant
        postgresql_hba_entries:
          - { type: host, database: all, user: all, address: '0.0.0.0/0', auth_method: md5 }
        postgresql_global_config_options:
          - option: listen_addresses
            value: '*'
image

I had the same issue, so just put the log_directory param in there as well, same value as the default That seems to make it happy

stale[bot] commented 1 year ago

This issue is no longer marked for closure.

pavlozt commented 1 year ago

Still actual

cristianrat commented 1 year ago

Still actual

indeed check my solution above, perhaps it works for you as well

pavlozt commented 1 year ago

Still actual

indeed check my solution above, perhaps it works for you as well

Of course, I have no problem finding the workaround. This issue should be investigated and fixed in this repository.

cristianrat commented 1 year ago

I agree :)

On Mon, Mar 20, 2023 at 6:51 PM pavlozt @.***> wrote:

Still actual

indeed check my solution above, perhaps it works for you as well

Of course, I have no problem finding the workaround. This issue should be investigated and fixed in this repository.

— Reply to this email directly, view it on GitHub https://github.com/geerlingguy/ansible-role-postgresql/issues/217#issuecomment-1476762598, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALFYCRHJI564MXJW2Y4VED3W5CRKJANCNFSM53IQTXGQ . You are receiving this because you commented.Message ID: @.***>

MalteKiefer commented 1 year ago

Can somebody help me, this is my playbook. I still get the same error:

- hosts: database
  become: yes
  pre_tasks:
    - name: Update repositories cache
      apt:
        update_cache: yes
  roles:
    - role: geerlingguy.postgresql
      vars:
        postgresql_restarted_state: "restarted"
        postgresql_service_state: started
        postgresql_service_enabled: true
        postgresql_auth_method: 'scram-sha-256'
        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: "scram-sha-256"}
          - {type: host, database: all, user: all, address: '::1/128', auth_method: "scram-sha-256"}
          - {type: host, database: all, user: all, address: '0.0.0.0/0', auth_method: "scram-sha-256"}
          - {type: host, database: all, user: all, address: '::/0', auth_method: "scram-sha-256"}
        postgresql_global_config_options:
          - option: listen_addresses
            value: '*'

- name: Open Postgres Port
  hosts: database
  tasks:
    - name: Allow Postgres
      community.general.ufw:
        rule: allow
        port: "5432"
        proto: tcp
Raptus1 commented 1 year ago

Hi,

You are missing the log_directory variable that you can find under defaults:

postgresql_global_config_options:

If you override the postgresql_global_config_options variable, you will need to also include the log_directory and it's value

On Tue, May 16, 2023, 06:04 Malte Kiefer @.***> wrote:

Can somebody help me, this is my playbook. I still get the same error:

  • hosts: database become: yes pre_tasks:

    • name: Update repositories cache apt: update_cache: yes roles:
    • role: geerlingguy.postgresql vars: postgresql_restarted_state: "restarted" postgresql_service_state: started postgresql_service_enabled: true postgresql_auth_method: 'scram-sha-256' 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: "scram-sha-256"}
      • {type: host, database: all, user: all, address: '::1/128', auth_method: "scram-sha-256"}
      • {type: host, database: all, user: all, address: '0.0.0.0/0', auth_method: "scram-sha-256"}
      • {type: host, database: all, user: all, address: '::/0', auth_method: "scram-sha-256"} postgresql_global_config_options:
      • option: listen_addresses value: '*'
  • name: Open Postgres Port hosts: database tasks:

    • name: Allow Postgres community.general.ufw: rule: allow port: "5432" proto: tcp

— Reply to this email directly, view it on GitHub https://github.com/geerlingguy/ansible-role-postgresql/issues/217#issuecomment-1548947335, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGKKOYWYXLV6PFI5W3BYWULXGL4EPANCNFSM53IQTXGQ . You are receiving this because you commented.Message ID: @.***>

charlfields commented 1 year ago

After adding the option: log_directory, it kinda works! I get the following error and I need to restart postgresql manually TASK [geerlingguy.postgresql : Ensure PostgreSQL users are present.] ***** failed: [208.83.232.178] (item=None) => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false} fatal: [208.83.232.178]: FAILED! => {"censored": "the output has been hidden due to the fact that 'no_log: true' was specified for this result", "changed": false}

github-actions[bot] commented 11 months ago

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

github-actions[bot] commented 9 months ago

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.