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

ssh_copy_id task not working for hashed hostnamed #179

Open
RedCarsten opened this issue Jul 20, 2023 · 0 comments
Open

ssh_copy_id task not working for hashed hostnamed #179

RedCarsten opened this issue Jul 20, 2023 · 0 comments

Comments

@RedCarsten
Copy link

If ssh uses the HashKnownHosts yes directive then the entries in the ~/.ssh/known_hosts file do not contain the hostname or IP in clear text.
As a consequence the step

https://github.com/IBM/Ansible-OpenShift-Provisioning/blob/main/roles/ssh_copy_id/tasks/main.yaml#L7

- name: Delete SSH key from known hosts if it already exists for idempotency
  tags: ssh_copy_id, ssh
  lineinfile:
    path: "~/.ssh/known_hosts"
    search_string: "{{ ssh_target[0] }}"
    state: absent

A solution that works with any config is to run instead:

ssh-keygen -f "~/.ssh/known_hosts" -R "{{ ssh_target[0] }}"

The alternative is to explicitly make sure that hostnames are not hashed, e.g. via the ssh config:

Host *
    HashKnownHosts no

Looks like the default is yes at least for ubuntu 22.04 (in /etc/ssh/ssh_config)

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

No branches or pull requests

1 participant