2 # Copyright 2015, Rackspace US, Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 - name: Ensure root has a .ssh directory
26 - name: Check for existing ssh private key file
28 path: /root/.ssh/id_rsa
29 register: ssh_key_private
33 - name: Check for existing ssh public key file
35 path: /root/.ssh/id_rsa.pub
36 register: ssh_key_public
40 - name: Remove an existing private/public ssh keys if one is missing
42 path: "/root/.ssh/{{ item }}"
44 when: not ssh_key_public.stat.exists or not ssh_key_private.stat.exists
51 - name: Create ssh key pair for root
56 ssh_key_file: /root/.ssh/id_rsa
60 - name: Fetch the generated public ssh key
62 src: "/root/.ssh/id_rsa.pub"
63 dest: "/tmp/id_rsa.pub"
65 when: inventory_hostname == groups['all'][0]
69 - name: Ensure root's new public ssh key is in authorized_keys
72 key: "{{ lookup('file','/tmp/id_rsa.pub') }}"