--- # 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: - "{{ swift_system_home_folder }}/.ssh/authorized_keys" - "{{ swift_system_home_folder }}/.ssh/id_rsa" - "{{ swift_system_home_folder }}/.ssh/id_rsa.pub" tags: - swift-key - swift-key-create - name: Create the swift SSH key if it doesnt exist command: | ssh-keygen -f {{ swift_system_home_folder }}/.ssh/id_rsa -t rsa -q -N "" sudo: yes sudo_user: "{{ swift_system_user_name }}" tags: - swift-key - swift-key-create - name: Create empty 'authorized_keys' file file: path: "{{ swift_system_home_folder }}/.ssh/authorized_keys" state: "touch" tags: - swift-key - swift-key-create - name: Change permissions on the generated keys file: path: "{{ item.path }}" group: "{{ swift_system_user_name }}" owner: "{{ swift_system_user_name }}" mode: "{{ item.mode }}" with_items: - { path: "{{ swift_system_home_folder }}/.ssh/authorized_keys", mode: "0700" } - { path: "{{ swift_system_home_folder }}/.ssh/id_rsa", mode: "0600" } - { path: "{{ swift_system_home_folder }}/.ssh/id_rsa.pub", mode: "0644" } tags: - swift-key - swift-key-create - name: Get public key contents command: | cat {{ swift_system_home_folder }}/.ssh/id_rsa.pub register: swift_pub changed_when: false tags: - swift-key - swift-key-create - name: Build authorized keys shell: | echo "{{ swift_pub.stdout }}" | tee -a {{ swift_system_home_folder }}/.ssh/authorized_keys delegate_to: "{{ groups['swift_hosts'][0] }}" tags: - swift-key - swift-key-create