Skip to content

Instantly share code, notes, and snippets.

@mgedmin
Created October 19, 2017 15:21
Show Gist options
  • Save mgedmin/65b797562edff34f05c560e91de799c5 to your computer and use it in GitHub Desktop.
Save mgedmin/65b797562edff34f05c560e91de799c5 to your computer and use it in GitHub Desktop.
Ansible playbook to install SSH host keys in known_hosts
# Ansible playbook that installs host keys for all of my servers into ~/.ssh/known_hosts
# group_vars/all has to list them all like
#
# ssh_host_keys:
# github: |
# github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
# fridge: |
# fridge.pov.lt ssh-dss ...
# fridge.pov.lt ssh-rsa ...
#
# You can get the keys themselves by doing cat /etc/ssh/ssh_host*_key.pub on each server
- hosts: localhost
gather_facts: no
tasks:
- name: set up ~/.ssh/known_hosts
lineinfile:
dest: ~/.ssh/known_hosts
line: "{{ item }}"
create: yes
with_items: "{{ ''.join(ssh_host_keys.values()).splitlines()|sort }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment