question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Failed to write to file .ssh/known_hosts: [Errno 2] No such file or directory: '.ssh/tmpupg6c51q'

See original GitHub issue

I have task the that runs the known_hosts module with a loop and multiple items.

It mostly works, except when I run the playbook with mitogen from within a centos7 docker container (e.g., in a CI/CD pipeline). Here is the “works/fails” matrix I tested:

mitogen Fedora WS centos7 docker
yes works fails
no works works

System facts:

  • ansible 2.8.3
  • mitogen 0.2.8 and git master
  • centos7 Docker container
  • Target system: Python: 3.6 (system)
  • Where ansible is run: Python 3.7 (conda)

The minimal playbook:

# hosts.yaml
all:
  hosts:
    myhost:
      ansible_host: host.example.com
  vars:
    ansible_python_interpreter: /usr/bin/python3.6
    ansible_user: myuser
# debug.yaml
- hosts: myhost
  gather_facts: False  # Speed-up deployments since we don't need these facts
  tasks:
    - name: Add/update public keys in kown_hosts
      known_hosts:
        name: "{{ item.host }}"
        key: "{{ item.key }}"
        path: .ssh/known_hosts
      loop:
       - {host: a, key: 'a,1.2.3.4 ecdsa-sha2-nistp256 ABCD1234'}
       - {host: b, key: 'b,5.6.7.8 ecdsa-sha2-nistp256 EFGH5678'}

The first item always works, but from the second item on, it fails like this:

...
TASK [Add/update public keys in kown_hosts] *************************************************************************
ok: [myhost] => (item={'host': 'a', 'key': 'a,1.2.3.4 ecdsa-sha2-nistp256 ABCD1234'})
failed: [myhost] (item={'host': 'b', 'key': 'b,5.6.7.8 ecdsa-sha2-nistp256 EFGH5678'}) => {"ansible_loop_var": "item", "changed": false, "item": {"host": "b", "key": "b,5.6.7.8 ecdsa-sha2-nistp256 EFGH5678"}, "msg": "Failed to write to file .ssh/known_hosts: [Errno 2] No such file or directory: '.ssh/tmpupg6c51q'"}

The the log with -vvv is attached: ansible.log

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dwcommented, Aug 23, 2019

This is a wonderfully concise bug report, thanks for for that. That it is a temp file suggests something may be going wrong with Mitogen’s “automatic leaked file descriptor cleanup” logic, but possibly it could be Yet Another Temp File issue due to the compatibility insanity inherited from Ansible 😃

I’ll try to setup a repro for this later, if it’s the auto cleanup code it’s probably a 1 liner fix. Thanks for reporting!

0reactions
dwcommented, Aug 24, 2019

That sounds fine. It’s probably something like a corner case in the extension because it’s a loop

Read more comments on GitHub >

github_iconTop Results From Across the Web

ssh/known_hosts: No such file or directory - Stack Overflow
The problem is, however, that when I'm trying to run a command like /.ssh$ .ssh/known_hosts gitlab.com ssh-ed25519 ... I get this error. I've ......
Read more >
Why does SSH think I still have a 'known_hosts2' file?
To fix $HOME/.ssh/known_hosts2: No such file or directory , you can add a file for UserKnownHostsFile to your SSH config, such as:
Read more >
Linux sysadmin basics: Troubleshooting known_hosts failures
SSH is easy to use, but when something causes your known_hosts to backfire on you, it can be frustrating. Here's how to fix...
Read more >
Clearing the known_hosts SSH File | Research Computing | RIT
Host key verification failed. The purpose of the known_hosts file is for the client to authenticate the server they are connecting to. This...
Read more >
SSH connection problem with "Host key verification failed ...
"Host key verification failed" means that the host key of the remote host was changed. SSH stores the host keys of the remote...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found