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