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

Module haproxy times out instead setting HAProxy backends into DRAIN mode followed by MAINT when the Backend is down / unreachable #8092

Closed
1 task done
BachenbergS opened this issue Mar 14, 2024 · 4 comments · Fixed by #8100
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type)

Comments

@BachenbergS
Copy link
Contributor

BachenbergS commented Mar 14, 2024

Summary

This is a similar bug to: https://github.com/ansible-collections/community.general

HAProxy allows setting backends into DRAIN mode, which waits until the server has no active connections before transitioning them into MAINT mode.

The corresponding Ansible haproxy module offers a state and parameter named 'drain' to achieve this functionality.

However, if the backend is unreachable and thus in a failed state, the haproxy module times out and fails instead of entering MAINT mode. The expected behavior would be to either directly fail or bypass the DRAIN mode and enter MAINT immediately.

Additionally, I noticed that "drain: true" does not work properly unless "wait: true" is also specified. Therefore, "wait: true" should be a mandatory parameter when using "drain: true".

I would appreciate it if this issue could be investigated and fixed.

Thank you for your time and consideration.

Issue Type

Bug Report

Component Name

haproxy

Ansible Version

$ ansible --version
ansible [core 2.16.4]
  config file = /home/user/stuff/ansible/ansible.cfg
  configured module search path = ['/home/user/stuff/ansible/plugins/library']
  ansible python module location = /usr/lib/python3.12/site-packages/ansible
  ansible collection location = /home/user/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.12.2 (main, Feb 21 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True

Community.general Version

$ ansible-galaxy collection list community.general
# /home/user/.ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 5.6.0  

# /usr/lib/python3.12/site-packages/ansible_collections
Collection        Version
----------------- -------
community.general 8.4.0  

Configuration

$ ansible-config dump --only-changed

OS / Environment

testet on RHEL 7 - 9

Steps to Reproduce

# the backend needs to be DOWN
    - name: Set backend state
      community.general.haproxy:
        state: disabled
        host: "{{ _host }}"
        socket: /tmp/haproxy.admin.sock
        wait: true
        drain: true
        wait_interval: 5
        wait_retries: 25
      become: true

Expected Results

The expected behavior would be to either directly fail or bypass the DRAIN mode and enter MAINT immediately.

Actual Results

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@ansibullbot
Copy link
Collaborator

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) labels Mar 14, 2024
@BachenbergS
Copy link
Contributor Author

This could be fixed by changing plugins/modules/haproxy.py line 344 to:
if state is not None and wait_for_status is not "DRAIN" and state is not "DOWN":

@BachenbergS
Copy link
Contributor Author

BachenbergS commented Mar 15, 2024

This could be fixed by changing plugins/modules/haproxy.py line 344 to: if state is not None and wait_for_status is not "DRAIN" and state is not "DOWN":

I moved my fix two lines down. This ensures that the backend is still set to DRAIN and only the wait is skipped. If the backend is set to DRAIN and the server is unreachable, it will remain in the DOWN state. However, if it comes back up during this time, it will switch to DRAIN. Otherwise, it would go back to UP in the worst case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module plugins plugin (any type)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants