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

Testinfra fails if the "~/.ansible/cp" path doesn't exist #735

Closed
koef opened this issue Sep 18, 2023 · 2 comments · Fixed by #763
Closed

Testinfra fails if the "~/.ansible/cp" path doesn't exist #735

koef opened this issue Sep 18, 2023 · 2 comments · Fixed by #763

Comments

@koef
Copy link

koef commented Sep 18, 2023

Hello,

After updating to release v9.0.0, we've noticed a regression. When the "~/.ansible/cp" path is missing, tests seem to fail with the following error:

self = <testinfra.backend.ssh.SshBackend object at 0x10199f3d0>
command = 'uname -s'

    def run_ssh(self, command: str) -> base.CommandResult:
        cmd, cmd_args = self._build_ssh_command(command)
        out = self.run_local(" ".join(cmd), *cmd_args)
        out.command = self.encode(command)
        if out.rc == 255:
            # ssh exits with the exit status of the remote command or with 255
            # if an error occurred.
>           raise RuntimeError(out)
E           RuntimeError: CommandResult(command=b'uname -s', exit_status=255, stdout=None, stderr=b"Warning: Permanently added '192.168.1.87' (ED25519) to the list of known hosts.\r\nunix_listener: cannot bind to path /Users/user/.ansible/cp/192.168.1.87-22-some-user.8yRLDJr64HeCjBh0: No such file or directory\r\n")

cmd        = ['ssh',
 '-F %s',
 '-o User=%s',
 '-o Port=%s',
 '-o ConnectTimeout=10',
 '-o ControlMaster=auto -o ControlPersist=60s',
 '-o ControlPath=~/.ansible/cp/%%h-%%p-%%r',
 '%s %s']
cmd_args   = ['../../../_molecule_resources/default/ssh_config',
 'some-user',
 '22',
 '192.168.1.87',
 'uname -s']
command    = 'uname -s'
out        = CommandResult(command=b'uname -s', exit_status=255, stdout=None, stderr=b"Warning: Permanently added '192.168.1.87' (ED25519) to the list of known hosts.\r\nunix_listener: cannot bind to path /Users/user/.ansible/cp/192.168.1.87-22-some-user.8yRLDJr64HeCjBh0: No such file or directory\r\n")
self       = <testinfra.backend.ssh.SshBackend object at 0x10199f3d0>

I believe the root cause might be associated with PR #713.

It might be beneficial for Testinfra to verify if the "directory" exists prior to it's utilization.

Thank you for looking into this.

@CarstenGrohmann
Copy link
Contributor

ControlPath will be set if control_path is set in section [ssh_connection] in ´ansible.cfg. You can uncomment control_path` to deactivate this feature.

Your suggestion sounds plausible. I'll see how it can be implemented.

@CarstenGrohmann
Copy link
Contributor

I've added a check for the existance of the Ansible SSH control path (default ~/.ansible/cp).

I hope this helps.

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

Successfully merging a pull request may close this issue.

2 participants