Skip to content

Instantly share code, notes, and snippets.

@bsanders
Created November 24, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bsanders/5b147a1344cb204f900b to your computer and use it in GitHub Desktop.
Save bsanders/5b147a1344cb204f900b to your computer and use it in GitHub Desktop.
psuedo-ansible
# I have all my hosts' public keys in a local directory ./keys/hosts/*pub
# I want to use the known_hosts module to add these to 'server'
# I'd prefer to just add the key to that local dir, and ansible just glob it up automatically
- hosts: server
vars:
# this is the part I'd like to do automatically;
# just loop over everything in "keys/hosts/" without explicitly repeating each file
ssh_pub_keys:
- name: host1
key: "{{ lookup('file', 'keys/hosts/host1.pub') }}"
- name: host2
key: "{{ lookup('file', 'keys/hosts/host2.pub') }}"
#- name: et cetera...
# ....
tasks:
- name: Add host pub key to server
known_hosts:
name: "{{ item.name }}"
key: "{{ item.key }}"
with_items: ssh_pub_keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment