Created
October 3, 2017 16:49
-
-
Save ianling/844802d9701b5fc2677d3bbc12899604 to your computer and use it in GitHub Desktop.
Ansible Playbook for generating and adding SSH certificates for a user on remote hosts
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
--- | |
- name: Set up sshcerts for ianl | |
hosts: all | |
remote_user: ianl | |
tasks: | |
- name: Generate a unique key for each host | |
local_action: command /usr/bin/ssh-keygen -b 2048 -t rsa -f /home/ianl/sshkeys/{{ inventory_hostname }} -q -N "" | |
become: no | |
- name: Create ~/.ssh directory | |
file: path=/home/ianl/.ssh state=directory owner=ianl group=ianl mode=0700 recurse=yes | |
- name: Add ssh key to user | |
authorized_key: user=ianl | |
key="{{ lookup('file', '/home/ianl/sshkeys/'+inventory_hostname+'.pub') }}" | |
state=present |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment