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

bug: missing until for retry in gce plugin #288

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cnfrancis
Copy link
Contributor

Missing the until key for the wait_for module in the gce plugin. Apparently, it doesn't work when the until is missing.
image

@cnfrancis cnfrancis changed the title fix: missing until for retry in gce plugin bug: missing until for retry in gce plugin Dec 19, 2024
@oraNod oraNod added the gce label Dec 19, 2024
@oraNod oraNod added the patch Bug fixes and small changes label Dec 19, 2024
@apatard
Copy link
Member

apatard commented Dec 20, 2024

You're patching the Linux file. What about its WINRM counterpart ? I guess it may suffer of the same kind of issue ?

@cnfrancis
Copy link
Contributor Author

cnfrancis commented Jan 9, 2025

You're patching the Linux file. What about its WINRM counterpart ? I guess it may suffer of the same kind of issue ?

yes (added the same for winrm), but actually I wonder if it's because of this line in the wait_for module code, perhaps some leaky error that can't quite be captured using only ansible language as the python code isn't wrapped in a try except or using a retry.

I re-reviewed the error I shared and the failed = false, so my change although making this more robust, I believe still doesn't cover this case.
image

what do you think @apatard ?

edit: I think we should be good, i tested locally with this:

import socket
import threading
import struct

count=0
def malicious_server():
    server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server.bind(("localhost", 12345))
    server.listen(1)
    while True:
        global count
        client, addr = server.accept()
        if count > 5:
            print("SSH")
            client.send("SSH\n".encode())
            client.close()
            break
        # Immediately close the connection with RST by setting SO_LINGER
        l_onoff = 1
        l_linger = 0
        client.setsockopt(
            socket.SOL_SOCKET, socket.SO_LINGER, struct.pack("ii", l_onoff, l_linger)
        )
        client.close()
        print(count)
        count+=1


# Start the server in a separate thread
server_thread = threading.Thread(target=malicious_server)
# server_thread.daemon = True
server_thread.start()
---
- name: Test waitfor
  hosts: localhost
  gather_facts: false
  remote_user: cnfrancis
  connection: local
  tasks:
    - name: Wait for SSH
      ansible.builtin.wait_for:
        port: 12345
        host: "localhost"
        search_regex: SSH
        delay: 0
      register: waitfor
      until: waitfor.failed == false
      retries: 6
      delay: 1
    - name: Print output
      ansible.builtin.debug:
        msg:
          # - "{{ waitfor }}"
          - "{{ waitfor }}"

TASK [Wait for SSH] ******************************************************************************************************
FAILED - RETRYING: [localhost]: Wait for SSH (6 retries left).
FAILED - RETRYING: [localhost]: Wait for SSH (5 retries left).
FAILED - RETRYING: [localhost]: Wait for SSH (4 retries left).
FAILED - RETRYING: [localhost]: Wait for SSH (3 retries left).
FAILED - RETRYING: [localhost]: Wait for SSH (2 retries left).
FAILED - RETRYING: [localhost]: Wait for SSH (1 retries left).
ok: [localhost]

TASK [Print output] ******************************************************************************************************
ok: [localhost] => {
    "msg": [
        {
            "attempts": 7,
            "changed": false,
            "elapsed": 0,
            "failed": false,
            "match_groupdict": {},
            "match_groups": [],
            "path": null,
            "port": 12345,
            "search_regex": "SSH",
            "state": "started"
        }
    ]
}

PLAY RECAP ***************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gce patch Bug fixes and small changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants