Removing SSH host keys from AWX

1 minute read Published: 2021-02-17

I had to figure out a way to remove specific hosts that had generated new host keys from the SSH known hosts file on the AWX system. What I came up with is the following playbook:

- hosts: all
  gather_facts: false
  tasks:
  - name: Remove host key from known_hosts
    command:
      cmd: ssh-keygen -R {{ inventory_hostname }}
    delegate_to: "localhost"

I just run this playbook with the limit set to the host or hosts I want to clear and have setup a template that just asks me for that limit.

I known that there is a module known_hosts, but it has a shortcoming in my opinion: It points to ~/.ssh/known\_hosts by default instead of parsing the ~/.ssh/config file to determine the default location.

#ansible #awx