Last active
September 6, 2016 02:29
-
-
Save nicolas17/29b8904c5f6d25896c596548857f487e to your computer and use it in GitHub Desktop.
Ansible ssh keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- hosts: default | |
remote_user: root | |
vars: | |
users: | |
- foo | |
- bar | |
- baz | |
- quux | |
keys: {} | |
tasks: | |
- name: gather SSH keys | |
set_fact: | |
keys: "{{ {item: lookup('fileglob','keydir/'+item+'@key*.pub', wantlist=True) | sort} | combine(keys) }}" | |
with_items: "{{users}}" | |
- name: check that SSH keys exist | |
assert: | |
that: "{{keys[item] | length != 0}}" | |
msg: "user '{{item}}' doesn't exist or has no keys" | |
with_items: "{{users}}" | |
- name: setup SSH keys for root | |
template: src=ssh_keys.j2 dest=/root/.ssh/authorized_keys |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for user in users: %} | |
# {{user}} | |
{% for keyfile in keys[user] %} | |
{{ lookup('file', keyfile) }} | |
{% endfor %} | |
{% endfor %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment