- name: Purge host from known hosts hosts: localhost gather_facts: no tasks: - command: ssh-keygen -f ~/.ssh/known_hosts -R [{{ item }}]:{{ hostvars[hostname].ansible_port }} with_items: - "{{ hostvars[hostname].ansible_host }}" - r3-{{ hostname }} - r3g-{{ hostname }} - r3e-{{ hostname }} - "{{ hostvars[hostname].network_cooked.primary.ip }}"