ansible / ansible.builtin / v2.4.0.0-1 / module / known_hosts Add or remove a host from the C(known_hosts) file | "added in version" 1.9 of ansible.builtin" Authors: Matthew Vernon (@mcv21) preview | supported by communityansible.builtin.known_hosts (v2.4.0.0-1) — module
pip
Install with pip install ansible==2.4.0.0.post1
The C(known_hosts) module lets you add or remove a host keys from the C(known_hosts) file.
Starting at Ansible 2.2, multiple entries per host are allowed, but only one for each key type supported by ssh. This is useful if you're going to want to use the M(git) module over ssh, for example.
If you have a very large number of host keys to manage, you will find the M(template) module more useful.
- name: tell the host about our servers it might want to ssh to known_hosts: path: /etc/ssh/ssh_known_hosts name: foo.com.invalid key: "{{ lookup('file', 'pubkeys/foo.com.invalid') }}"
key: default: null description: - The SSH public host key, as a string (required if state=present, optional when state=absent, in which case all keys for the host are removed). The key must be in the right format for ssh (see sshd(8), section "SSH_KNOWN_HOSTS FILE FORMAT") required: false name: aliases: - host default: null description: - The host to add or remove (must match a host specified in key). It will be converted to lowercase so that ssh-keygen can find it. required: true path: default: (homedir)+/.ssh/known_hosts description: - The known_hosts file to edit required: false state: choices: - present - absent default: present description: - I(present) to add the host key, I(absent) to remove it. required: false hash_host: default: false description: - Hash the hostname in the known_hosts file required: false version_added: '2.3' version_added_collection: ansible.builtin