--- # Copyright 2014, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - name: Remove old key file(s) if found file: path: "{{ item }}" state: "absent" with_items: - "{{ nova_system_home_folder }}/.ssh/authorized_keys" - "{{ nova_system_home_folder }}/.ssh/id_rsa" - "{{ nova_system_home_folder }}/.ssh/id_rsa.pub" tags: - nova-key - nova-key-create - name: Create the nova SSH config file copy: src: "ssh_config" dest: "/var/lib/nova/.ssh/config" owner: "{{ nova_system_user_name }}" group: "{{ nova_system_user_name }}" mode: "0644" tags: - nova-key - nova-key-create - name: Create the nova SSH key if it doesnt exist command: | ssh-keygen -f {{ nova_system_home_folder }}/.ssh/id_rsa -t rsa -q -N "" sudo: yes sudo_user: "{{ nova_system_user_name }}" tags: - nova-key - nova-key-create - name: Create empty 'authorized_keys' file file: path: "{{ nova_system_home_folder }}/.ssh/authorized_keys" state: "touch" tags: - nova-key - nova-key-create - name: Change permissions on the generated keys file: path: "{{ item.path }}" group: "{{ nova_system_user_name }}" owner: "{{ nova_system_user_name }}" mode: "{{ item.mode }}" with_items: - { path: "{{ nova_system_home_folder }}/.ssh/authorized_keys", mode: "0700" } - { path: "{{ nova_system_home_folder }}/.ssh/id_rsa", mode: "0600" } - { path: "{{ nova_system_home_folder }}/.ssh/id_rsa.pub", mode: "0644" } tags: - nova-key - nova-key-create - name: Get public key contents command: | cat {{ nova_system_home_folder }}/.ssh/id_rsa.pub register: nova_pub changed_when: false tags: - nova-key - nova-key-create - name: Build authorized keys shell: | echo "{{ nova_pub.stdout }}" | tee -a {{ nova_system_home_folder }}/.ssh/authorized_keys delegate_to: "{{ groups['nova_compute'][0] }}" tags: - nova-key - nova-key-create