Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit 29b62f7 introduces ZeroDivisionError error due to missing devture_postgres_max_parallel_workers_per_gather passed to com.devture.ansible.role.postgres #2953

Closed
matthewrfennell opened this issue Oct 18, 2023 · 1 comment

Comments

@matthewrfennell
Copy link

matthewrfennell commented Oct 18, 2023

Describe the bug

git pull # gets 29b62f7
make roles
ansible-playbook -i inventory/hosts setup.yml --tags=setup-all,start
TASK [galaxy/com.devture.ansible.role.postgres : Ensure Postgres systemd service installed] ***
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleError: An unhandled exception occurred while templating '{{ devture_postgres_postgres_process_extra_arguments_auto + devture_postgres_postgres_process_extra_arguments_custom }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '["-c 'max_connections={{ devture_postgres_max_connections|int }}'", "-c 'shared_buffers={{ (devture_postgres_shared_buffers|int/1024)|int }}MB'", "-c 'effective_cache_size={{ (devture_postgres_effective_cache_size|int/1024)|int }}MB'", "-c 'maintenance_work_mem={{ (devture_postgres_maintenance_work_mem|int/1024)|int }}MB'", "-c 'checkpoint_completion_target={{ devture_postgres_checkpoint_completion_target }}'", "-c 'wal_buffers={{ (devture_postgres_wal_buffers|int/1024)|int }}MB'", "-c 'default_statistics_target={{ devture_postgres_default_statistics_target|int }}'", "-c 'random_page_cost={{ devture_postgres_random_page_cost }}'", "-c 'effective_io_concurrency={{ devture_postgres_effective_io_concurrency|int }}'", "-c 'work_mem={{ devture_postgres_work_mem|int }}kB'", "-c 'huge_pages={{ devture_postgres_huge_pages }}'", "-c 'min_wal_size={{ (devture_postgres_min_wal_size|int/1024)|int }}MB'", "-c 'max_wal_size={{ (devture_postgres_max_wal_size|int/1024)|int }}MB'", "-c 'max_worker_processes={{ devture_postgres_max_worker_processes|int }}'", "-c 'max_parallel_workers={{ devture_postgres_max_parallel_workers|int }}'", "-c 'max_parallel_workers_per_gather={{ devture_postgres_max_parallel_workers_per_gather|int }}'", "-c 'max_parallel_maintenance_workers={{ devture_postgres_max_parallel_maintenance_workers|int }}'"]'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ '64' if devture_postgres_work_mem_raw|int <= 64 else devture_postgres_work_mem_raw|int }}'. Error was a <class 'ansible.errors.AnsibleError'>, original message: An unhandled exception occurred while templating '{{ ((devture_postgres_memtotal_kb|int - devture_postgres_shared_buffers|int)/(devture_postgres_max_connections|int*3))/devture_postgres_max_parallel_workers_per_gather|int }}'. Error was a <class 'ZeroDivisionError'>, original message: float division by zero
fatal: [redacted]: FAILED! => changed=false 
  msg: 'AnsibleError: An unhandled exception occurred while templating ''{{ devture_postgres_postgres_process_extra_arguments_auto + devture_postgres_postgres_process_extra_arguments_custom }}''. Error was a <class ''ansible.errors.AnsibleError''>, original message: An unhandled exception occurred while templating ''["-c ''max_connections={{ devture_postgres_max_connections|int }}''", "-c ''shared_buffers={{ (devture_postgres_shared_buffers|int/1024)|int }}MB''", "-c ''effective_cache_size={{ (devture_postgres_effective_cache_size|int/1024)|int }}MB''", "-c ''maintenance_work_mem={{ (devture_postgres_maintenance_work_mem|int/1024)|int }}MB''", "-c ''checkpoint_completion_target={{ devture_postgres_checkpoint_completion_target }}''", "-c ''wal_buffers={{ (devture_postgres_wal_buffers|int/1024)|int }}MB''", "-c ''default_statistics_target={{ devture_postgres_default_statistics_target|int }}''", "-c ''random_page_cost={{ devture_postgres_random_page_cost }}''", "-c ''effective_io_concurrency={{
    devture_postgres_effective_io_concurrency|int }}''", "-c ''work_mem={{ devture_postgres_work_mem|int }}kB''", "-c ''huge_pages={{ devture_postgres_huge_pages }}''", "-c ''min_wal_size={{ (devture_postgres_min_wal_size|int/1024)|int }}MB''", "-c ''max_wal_size={{ (devture_postgres_max_wal_size|int/1024)|int }}MB''", "-c ''max_worker_processes={{ devture_postgres_max_worker_processes|int }}''", "-c ''max_parallel_workers={{ devture_postgres_max_parallel_workers|int }}''", "-c ''max_parallel_workers_per_gather={{ devture_postgres_max_parallel_workers_per_gather|int }}''", "-c ''max_parallel_maintenance_workers={{ devture_postgres_max_parallel_maintenance_workers|int }}''"]''. Error was a <class ''ansible.errors.AnsibleError''>, original message: An unhandled exception occurred while templating ''{{ ''64'' if devture_postgres_work_mem_raw|int <= 64 else devture_postgres_work_mem_raw|int }}''. Error was a <class ''ansible.errors.AnsibleError''>, original message: An unhandled exception occurred
    while templating ''{{ ((devture_postgres_memtotal_kb|int - devture_postgres_shared_buffers|int)/(devture_postgres_max_connections|int*3))/devture_postgres_max_parallel_workers_per_gather|int }}''. Error was a <class ''ZeroDivisionError''>, original message: float division by zero

To Reproduce
My vars.yml file looks like this:

devture_traefik_config_certificatesResolvers_acme_email: # redacted
matrix_coturn_turn_static_auth_secret: # redacted
matrix_domain: # redacted
matrix_homeserver_generic_secret_key: # redacted
matrix_ma1sd_enabled: false
matrix_mailer_enabled: false
matrix_nginx_proxy_base_domain_serving_enabled: true
devture_postgres_connection_password: # redacted
matrix_playbook_reverse_proxy_type: playbook-managed-traefik
matrix_ssl_lets_encrypt_support_email: # redacted
matrix_synapse_ext_password_provider_shared_secret_auth_enabled: true
matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret: # redacted
matrix_synapse_presence_enabled: false
matrix_synapse_auto_compressor_enabled: true
matrix_coturn_enabled: false

matrix_mautrix_telegram_enabled: true
matrix_mautrix_telegram_api_id: # redacted
matrix_mautrix_telegram_api_hash: # redacted
matrix_mautrix_telegram_configuration_extension_yaml: |
  bridge:
    encryption:
      allow: true
      default: true
    startup_sync: false
    federate_rooms: false
    displayname_template: "{displayname}"

matrix_mautrix_facebook_enabled: true
matrix_mautrix_facebook_configuration_extension_yaml: |
  bridge:
    initial_chat_sync: 1
    encryption:
      allow: true
      default: true
    displayname_template: "{displayname}"

matrix_mautrix_whatsapp_enabled: true
matrix_mautrix_whatsapp_configuration_extension_yaml: |
  bridge:
    initial_chat_sync: 1
    encryption:
      allow: true
      default: true
    displayname_template: "{{ '{{if .PushName}}{{.PushName}}{{else if .BusinessName}}{{.BusinessName}}{{else}}{{.JID}}{{end}}' }}"

matrix_beeper_linkedin_enabled: true
matrix_beeper_linkedin_configuration_extension_yaml: |
  bridge:
    encryption:
      allow: true
      default: true
    displayname_template: "{displayname}"

matrix_mautrix_discord_enabled: true
matrix_mautrix_discord_bridge_encryption_allow: true

matrix_client_element_enabled: false
devture_systemd_service_manager_up_verification_delay_seconds: 29

matrix_nginx_proxy_proxy_domain_additional_server_configuration_blocks:
  - |
    location = /.well-known/host-meta {
        return 301 # https://example.org$request_uri;
    }

matrix_nginx_proxy_base_domain_homepage_enabled: false

Expected behavior
I expect all variables to be passed through to the postgres project, without me having to manually specify overrides, and for no division by zero errors to occur. This happens as expected on commit 5ba6630 (the commit before 29b62f7).

Matrix Server:

  • OS: Debian 11.8
  • Architecture: amd64

Additional Context:
Adding this line to my vars.yaml fixes the issue on 29b62f7:

devture_postgres_max_parallel_workers_per_gather: 2
@matthewrfennell matthewrfennell changed the title Commit 29b62f7 introduces DivideByZero error due to missing max_parallel_workers_per_gather passed to com.devture.ansible.role.postgres Commit 29b62f7 introduces ZeroDivisionError error due to missing devture_postgres_max_parallel_workers_per_gather passed to com.devture.ansible.role.postgres Oct 18, 2023
@thedanbob
Copy link
Contributor

thedanbob commented Oct 19, 2023

I just encountered this. In the default config, the problem lines are:

devture_postgres_max_parallel_workers_per_gather: "{{ '4' if ansible_processor_nproc/2 > 4 else ansible_processor_nproc|int/2 }}"
...
devture_postgres_work_mem_raw: "{{ ((devture_postgres_memtotal_kb|int - devture_postgres_shared_buffers|int)/(devture_postgres_max_connections|int*3))/devture_postgres_max_parallel_workers_per_gather|int }}"

On my single core server ansible_processor_nproc is 1 so devture_postgres_max_parallel_workers_per_gather = 0.5. That means devture_postgres_max_parallel_workers_per_gather|int is zero. So technically this is a bug in the postgres role. I'll open a bug report there.

Edit: devture/com.devture.ansible.role.postgres#9

spantaleev added a commit that referenced this issue Oct 19, 2023
cvwright pushed a commit to cvwright/matrix-docker-ansible-deploy that referenced this issue Jan 11, 2024
KarolosLykos pushed a commit to KarolosLykos/matrix-docker-ansible-deploy that referenced this issue Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants