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
ssh connection reset and ssh tokens in controlpath #68341
Comments
Files identified in the description: If these files are inaccurate, please update the |
Any idea on how to fix this ? |
I think the code based fix will be something roughly like this: diff --git a/lib/ansible/plugins/connection/ssh.py b/lib/ansible/plugins/connection/ssh.py
index ed44a035fe..fa5ad29cf2 100644
--- a/lib/ansible/plugins/connection/ssh.py
+++ b/lib/ansible/plugins/connection/ssh.py
@@ -1266,7 +1266,7 @@ class Connection(ConnectionBase):
run_reset = False
if controlpersist and len(cp_arg) > 0:
cp_path = cp_arg[0].split(b"=", 1)[-1]
- if os.path.exists(cp_path):
+ if os.path.exists(cp_path) or re.search(r'%[hprC]', cp_path):
run_reset = True
elif controlpersist:
run_reset = True I haven't tested this, and am not actively pursuing this fix any further. If you want to test this, and get together a pull request, please feel free to do so. |
thanks. I'll test that. I guess this would work but I'm still worried about re-introducing bug #42991. |
reset now expands ssh tokens before checking path existence. Successfully tested with molecule and meta: reset_connection. Fix : ansible#68341 May Fix : ansible#66414
reset now expands ssh tokens before checking path existence. Successfully tested with molecule and meta: reset_connection. Fixes: ansible#68341
reset now expands ssh tokens before checking path existence. Successfully tested with molecule and meta: reset_connection. Fixes: ansible#68341
SUMMARY
When investigating ansible-community/molecule-vagrant#1, I found out that
meta: reset_connection
is not working due to the reset() function of the ssh.py connection plugin not being able to find the connection socket. It turns out that molecule is usingcontrol_path = %(directory)s/%%h-%%p-%%r
. For instance, it's translated intoControlPath=/home/vagrant/.ansible/cp/%h-%p-%r
on the ssh command line.The reset code does :
Due to the content of the ControlPath argument, it will set
cp_path
to/home/vagrant/.ansible/cp/%h-%p-%r
and of course, theos.path.exists(cp_path)
will fail, making "meta: reset_connection" useless.fwiw, looks like this bug as been introduced by the fix for #42991
A crude workaround would be changing the test to
if b'%' in cp_path or os.path.exists(cp_path)
. It may be better to interpolate the ssh tokens but I've no idea if it's really possible and how to do that.ISSUE TYPE
COMPONENT NAME
ssh connection plugin
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Debian stable
STEPS TO REPRODUCE
Since I was testing that for molecule-vagrant, I've a Vagrantfile and a converge.yml file:
Vagrantfile:
converge.yml
ansible.cfg
EXPECTED RESULTS
The run of the
converge.yml
should workACTUAL RESULTS
The text was updated successfully, but these errors were encountered: