-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclear-ssh.yml
33 lines (28 loc) · 1.05 KB
/
clear-ssh.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
- name: "Update ~/.ssh/known_host on localhost"
hosts: all
gather_facts: no
tasks:
- name: Compute path to known_host
ansible.builtin.set_fact:
known_host_path: "{{ lookup('env','HOME') }}/.ssh/known_hosts"
- name: Check if known_host exists
ansible.builtin.stat:
path: "{{ known_host_path }}"
register: known_host_stat
run_once: true
delegate_to: localhost
- name: "Remove hostname from ~/.ssh/known_host"
ansible.builtin.shell: "ssh-keygen -f '{{ known_host_path }}' -R '{{ inventory_hostname }}'"
when: known_host_stat.stat.exists
throttle: 1
delegate_to: localhost
- name: "Remove IP from ~/.ssh/known_host"
ansible.builtin.shell: "ssh-keygen -f '{{ known_host_path }}' -R '{{ ansible_ssh_host }}'"
when: known_host_stat.stat.exists
throttle: 1
delegate_to: localhost
- name: "ssh-keyscan IP to ~/.ssh/known_host"
ansible.builtin.shell: "ssh-keyscan -H '{{ ansible_ssh_host }}' >> '{{ known_host_path }}'"
throttle: 1
delegate_to: localhost