W3cubDocs

/Ansible

known_hosts - Add or remove a host from the known_hosts file

New in version 1.9.

Synopsis

The known_hosts module lets you add or remove a host keys from the 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 git module over ssh, for example. If you have a very large number of host keys to manage, you will find the template module more useful.

Options

parameter required default choices comments
key
no
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(1), section "SSH_KNOWN_HOSTS FILE FORMAT")
name
yes
The host to add or remove (must match a host specified in key)
aliases: host
path
no (homedir)+/.ssh/known_hosts
The known_hosts file to edit
state
no present
  • present
  • absent
present to add the host key, absent to remove it.

Examples

# Example using with_file to set the system known_hosts file
- 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') }}"

This is an Extras Module

For more information on what this means please read Extras Modules

For help in developing on modules, should you be so inclined, please read Community Information & Contributing, developing_test_pr and Developing Modules.

© 2012–2016 Michael DeHaan
© 2016 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/known_hosts_module.html