ansible.builtin.known_hosts – Add or remove a host from the known_hosts
file¶
Note
This module is part of ansible-base
and included in all Ansible
installations. In most cases, you can use the short module name
known_hosts even without specifying the collections:
keyword.
Despite that, we recommend you use the FQCN for easy linking to the module
documentation and to avoid conflicting with other collections that may have
the same module name.
New in version 1.9: of ansible.builtin
Synopsis¶
The
known_hosts
module lets you add or remove a host keys from theknown_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 ansible.builtin.git module over ssh, for example.
If you have a very large number of host keys to manage, you will find the ansible.builtin.template module more useful.
Parameters¶
Examples¶
- 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') }}"
- name: Another way to call known_hosts
known_hosts:
name: host1.example.com # or 10.9.8.77
key: host1.example.com,10.9.8.77 ssh-rsa ASDeararAIUHI324324 # some key gibberish
path: /etc/ssh/ssh_known_hosts
state: present
- name: Add host with custom SSH port
known_hosts:
name: '[host1.example.com]:2222'
key: '[host1.example.com]:2222 ssh-rsa ASDeararAIUHI324324' # some key gibberish
path: /etc/ssh/ssh_known_hosts
state: present
Authors¶
Matthew Vernon (@mcv21)