---
- hosts: all
  become: false
  vars:
    keyfile: /tmp/known_hosts
  tasks:
    - name: Add short name to file
      local_action: shell ssh-keyscan -p {{ansible_port|default(22)}} -H {{inventory_hostname}} 2> /dev/null >> {{keyfile}}
      ignore_errors: true

    - name: Add FQDN to file
      local_action: shell ssh-keyscan -p {{ansible_port|default(22)}} -H {{ansible_fqdn}} 2> /dev/null >> {{keyfile}}
      ignore_errors: true

    - name: Add IPv4 to file
      local_action: shell ssh-keyscan -p {{ansible_port|default(22)}} -H {{ansible_default_ipv4.address}} 2> /dev/null >> {{keyfile}}
      ignore_errors: true
