Failed to write to file .ssh/known_hosts: [Errno 2] No such file or directory: '.ssh/tmpupg6c51q'
See original GitHub issueI 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:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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!
That sounds fine. It’s probably something like a corner case in the extension because it’s a loop