Skip to content

Instantly share code, notes, and snippets.

@ianling
Created October 3, 2017 16:49
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 ianling/844802d9701b5fc2677d3bbc12899604 to your computer and use it in GitHub Desktop.
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
---
- 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