An ansible hook for adding/removing hosts from known_hosts files.
Switch branches/tags
Nothing to show
Latest commit abed772 Mar 16, 2015 @brycebaril brycebaril Merge pull request #9 from pulyaevskiy/add-owner-to-docs
Added docs for owner attribute


Add or remove a host from the known_hosts file using ansible.

This is especially useful for a new machine where you want to do something like use the 'git' module with ssh. If you don't prime the known_hosts file, ansible will hang because it is waiting for input you can't give it.

How To Use

Copy the known_hosts bash script into a library folder adjacent to your ansible playbook. You can then define a task like this:

- hosts: myhosts
  user: deploy
    - name: Ensure github is in the known_hosts file
      known_hosts: state=present


Required. The host to add or remove. Will also look up the IP address and add that as well.


The ssh port. Defaults to 22


The known_hosts file to append/remove the keys from. Defaults to $HOME/.ssh/known_hosts


'present' to add the host, 'absent' to remove it. Defaults to 'present'


Username of the owner of 'known_hosts' file, usually useful in case you specified custom filepath in 'file' attribute.


Python is considered good form for Ansible modules, but for now it was much easier to convert something I already had written in bash. It does the job, but I may some day convert it to Python in order to submit it to


MIT -- See LICENSE file.