Skip to content

Instantly share code, notes, and snippets.

@moreati
Created December 16, 2024 10:16
Show Gist options
  • Save moreati/697f90ab5ac7252ed1add937658348ca to your computer and use it in GitHub Desktop.
Save moreati/697f90ab5ac7252ed1add937658348ca to your computer and use it in GitHub Desktop.
Test ansible PR 84240 wrt connection timeout option
- hosts: d12.mynet
connection: ssh_noisy_get_option
gather_facts: false
vars:
ansible_python_interpreter: python3
tasks:
- meta: reset_connection
- ping:
from ansible.plugins.connection.ssh import (
Connection as Connection_,
DOCUMENTATION as DOCUMENTATION_,
)
from ansible.utils.display import Display
DOCUMENTATION = DOCUMENTATION_.replace(
' name: ssh\n',
' name: ssh_noisy_get_option\n',
)
display = Display()
class Connection(Connection_):
transport = 'ssh_noisy_get_option'
def get_option(self, option, hostvars=None):
result = super().get_option(option, hostvars=hostvars)
if option == 'timeout':
display.warning(f'ssh_noisy_get_option.get_option({option!r}, ...) -> {result!r}')
return result
[tox]
envlist =
py312-ansible{8,9,11,10.pr84240,11.pr84240,12.dev}
skipsdist = true
[testenv]
deps =
ansible8: ansible~=8.0
ansible9: ansible~=9.0
ansible10: ansible~=10.0
ansible11: ansible~=11.0
ansible10.pr84240: git+https://github.com/s-hertel/ansible.git@backport/2.17/84240
ansible11.pr84240: git+https://github.com/s-hertel/ansible.git@backport/2.18/84240
ansible12.dev: git+https://github.com/ansible/ansible.git@01ca9b1d0ec882f5eea7fc42ef7f7dab9ea76d19
setenv =
ANSIBLE_CONNECTION_PLUGINS={toxinidir}/lib/connection
ANSIBLE_PIPELINING=true
ANSIBLE_STDOUT_CALLBACK=default
commands =
ansible-playbook -i d12.mynet, connection_timeout.yml
@moreati
Copy link
Author

moreati commented Dec 16, 2024

ansible/ansible#84240 fixed templated connection actions during a meta: reset_connection. This gist is a check that it did not introduce a new bug: overwriting the ssh connection timeout (default 10 seconds) with the task timeout (set by timeout keyword, default 0 seconds) during meta: reset_connection (and possibly persisting beyond).

Based on this (slightly adhoc) testing, the answer is no - connection timeout retains the correct value (10), it is not overwritten.

$ tox -c tox_connection_timeout.ini 
py312-ansible8: commands[0]> ansible-playbook -i d12.mynet, connection_timeout.yml

PLAY [d12.mynet] **************************************************************************************************************************************************************************************************************

TASK [meta] *******************************************************************************************************************************************************************************************************************
[WARNING]: ssh_noisy_get_option.get_option('timeout', ...) -> 10

TASK [ping] *******************************************************************************************************************************************************************************************************************
ok: [d12.mynet]

PLAY RECAP ********************************************************************************************************************************************************************************************************************
d12.mynet                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

py312-ansible8: OK ✔ in 0.79 seconds
py312-ansible9: commands[0]> ansible-playbook -i d12.mynet, connection_timeout.yml

PLAY [d12.mynet] **************************************************************************************************************************************************************************************************************

TASK [meta] *******************************************************************************************************************************************************************************************************************
[WARNING]: ssh_noisy_get_option.get_option('timeout', ...) -> 10

TASK [ping] *******************************************************************************************************************************************************************************************************************
ok: [d12.mynet]

PLAY RECAP ********************************************************************************************************************************************************************************************************************
d12.mynet                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

py312-ansible9: OK ✔ in 0.71 seconds
py312-ansible11: commands[0]> ansible-playbook -i d12.mynet, connection_timeout.yml

PLAY [d12.mynet] **************************************************************************************************************************************************************************************************************

TASK [meta] *******************************************************************************************************************************************************************************************************************
[WARNING]: ssh_noisy_get_option.get_option('timeout', ...) -> 10

TASK [ping] *******************************************************************************************************************************************************************************************************************
ok: [d12.mynet]

PLAY RECAP ********************************************************************************************************************************************************************************************************************
d12.mynet                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

py312-ansible11: OK ✔ in 0.81 seconds
py312-ansible10.pr84240: commands[0]> ansible-playbook -i d12.mynet, connection_timeout.yml

PLAY [d12.mynet] **************************************************************************************************************************************************************************************************************

TASK [meta] *******************************************************************************************************************************************************************************************************************
[WARNING]: ssh_noisy_get_option.get_option('timeout', ...) -> 10

TASK [ping] *******************************************************************************************************************************************************************************************************************
ok: [d12.mynet]

PLAY RECAP ********************************************************************************************************************************************************************************************************************
d12.mynet                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

py312-ansible10.pr84240: OK ✔ in 0.65 seconds
py312-ansible11.pr84240: commands[0]> ansible-playbook -i d12.mynet, connection_timeout.yml

PLAY [d12.mynet] **************************************************************************************************************************************************************************************************************

TASK [meta] *******************************************************************************************************************************************************************************************************************
[WARNING]: ssh_noisy_get_option.get_option('timeout', ...) -> 10

TASK [ping] *******************************************************************************************************************************************************************************************************************
ok: [d12.mynet]

PLAY RECAP ********************************************************************************************************************************************************************************************************************
d12.mynet                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

py312-ansible11.pr84240: OK ✔ in 0.61 seconds
py312-ansible12.dev: commands[0]> ansible-playbook -i d12.mynet, connection_timeout.yml
[WARNING]: You are running the development version of Ansible. You should only run Ansible from "devel" if you are modifying the Ansible engine, or trying out features under development. This is a rapidly changing source
of code and can become unstable at any point.

PLAY [d12.mynet] **************************************************************************************************************************************************************************************************************

TASK [meta] *******************************************************************************************************************************************************************************************************************
[WARNING]: ssh_noisy_get_option.get_option('timeout', ...) -> 10

TASK [ping] *******************************************************************************************************************************************************************************************************************
ok: [d12.mynet]

PLAY RECAP ********************************************************************************************************************************************************************************************************************
d12.mynet                  : ok=1    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

  py312-ansible8: OK (0.78=setup[0.00]+cmd[0.78] seconds)
  py312-ansible9: OK (0.71=setup[0.00]+cmd[0.70] seconds)
  py312-ansible11: OK (0.81=setup[0.00]+cmd[0.81] seconds)
  py312-ansible10.pr84240: OK (0.65=setup[0.00]+cmd[0.65] seconds)
  py312-ansible11.pr84240: OK (0.61=setup[0.00]+cmd[0.60] seconds)
  py312-ansible12.dev: OK (0.69=setup[0.00]+cmd[0.69] seconds)
  congratulations :) (4.28 seconds)

@moreati
Copy link
Author

moreati commented Dec 16, 2024

The overwriting behaviour I saw while working on mitogen-hq/mitogen#1201 must be specific to Mitogen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment