update-known-hosts.yml (804B)
1 --- 2 3 # Local tasks to update known ssh hosts 4 # 5 # Remove: 6 # for ip in $(cat qemu-config.yml | grep ip4 | awk '{print $2}'); do ssh-keygen -R $ip; done 7 # 8 # Add: 9 # for host in $(cat qemu-config.yml | grep fqdn | awk '{print $3}'); do ssh -F ../ssh/config $host exit; done 10 # 11 # Requires './qemu-config.yml' with ipv4 addresses 12 - hosts: local 13 vars: 14 qemu_config: "{{ lookup('file', 'qemu-config.yml') | from_yaml }}" 15 tasks: 16 - name: remove the host from local known hosts 17 known_hosts: 18 path: '{{ ansible_env.HOME }}/.ssh/known_hosts' 19 name: '{{ item.ip4 }}' 20 state: absent 21 loop: '{{ qemu_config }}' 22 23 - name: update known host locally 24 shell: 'for host in $(cat qemu-config.yml | grep fqdn | awk "{print $3}"); do ssh -F ../ssh/config $host exit; done'