I have the following playbook:
---
- name: provision toms keys
hosts: ssh4.demo.com
tasks:
- name: ensure user tom is present
user: name=tom state=present
- name: ensure private key and public one are present
copy: src=ssh_keys/tom dest=/.ssh mode=0600
with_items:
- id_rsa.pub
- id_rsa
- name: provision toms public keys
hosts: ssh1.demo.com
sudo: yes
tasks:
- user: name=tom comment="Add tom" group=staff
- name: Placing key
authorized_key: user=tom key="{{ lookup('file', 'ssh_keys/tom/id_rsa.pub') }}"
I have a local directory that contains both my ssh public and private keys like this:
./ssh_keys
./ssh_keys/david
./ssh_keys/david/id_rsa
./ssh_keys/david/id_rsa.pub
./ssh_keys/fred
./ssh_keys/fred/id_rsa
./ssh_keys/fred/id_rsa.pub
./ssh_keys/joe
./ssh_keys/joe/id_rsa
./ssh_keys/joe/id_rsa.pub
./ssh_keys/paul
./ssh_keys/paul/id_rsa
./ssh_keys/paul/id_rsa.pub
./ssh_keys/peter
./ssh_keys/peter/id_rsa
./ssh_keys/peter/id_rsa.pub
./ssh_keys/tom
./ssh_keys/tom/id_rsa
./ssh_keys/tom/id_rsa.pub
I need to create some playbooks that can be used to push the keys to various hosts defined in the hosts fields.
However, the .ssh key directories are getting created incorrectly. i.e. a directory called tom gets created below an id_rsa and id_rsa.pub directory.
e.g.
/home/tom/.ssh/id_rsa/tom/id_rsa
Does anybody have a good example playbook for this ?