Jonathan Hart | 93956f5 | 2017-08-22 13:12:42 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 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 |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 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. |
| 15 | |
| 16 | |
Andy Bavier | 3833383 | 2017-06-19 09:55:35 -0400 | [diff] [blame] | 17 | # Fetch local user rather than relying on (deprecated) ansible_user |
| 18 | - name: Get the username running the deploy |
| 19 | local_action: command whoami |
| 20 | register: username_on_the_host |
| 21 | tags: |
| 22 | - establish_ssh_keys |
| 23 | - skip_ansible_lint |
| 24 | |
| 25 | # SSH Key access from the current machine to the target node is required for the |
| 26 | # synchronize action to work. |
| 27 | - name: Ensure User SSH Keys |
| 28 | local_action: user name='{{ username_on_the_host.stdout }}' generate_ssh_key=yes ssh_key_bits=2048 |
| 29 | tags: |
| 30 | - establish_ssh_keys |
| 31 | |
| 32 | - name: Ensure Key Authorized on Target Head Node |
| 33 | authorized_key: |
Andy Bavier | 4ae79c9 | 2017-07-27 13:02:11 -0700 | [diff] [blame] | 34 | user: '{{ansible_user_id}}' |
Andy Bavier | 3833383 | 2017-06-19 09:55:35 -0400 | [diff] [blame] | 35 | key: "{{lookup('file', '~/.ssh/id_rsa.pub')}}" |
| 36 | tags: |
| 37 | - establish_ssh_keys |
David K. Bainbridge | 0a7cdbb | 2017-07-14 11:36:13 -0700 | [diff] [blame] | 38 | |
| 39 | - name: Ensure key pair storage |
| 40 | become: yes |
| 41 | local_action: file path={{pub_ssh_key_file_location}} mode="0755" state=directory |
| 42 | |
| 43 | - name: Validate existing key pair |
| 44 | become: yes |
| 45 | local_action: stat path={{pub_ssh_key_file_location}}/cord_rsa |
| 46 | register: key_pair |
| 47 | |
| 48 | - name: Generate key pair |
| 49 | become: yes |
| 50 | local_action: command ssh-keygen -b 2048 -t rsa -N "" -C cord@cord.lab -f {{pub_ssh_key_file_location}}/cord_rsa |
| 51 | when: not key_pair.stat.exists |
| 52 | |
| 53 | - name: Ensure privacy of key pair |
| 54 | become: yes |
| 55 | local_action: file path="{{pub_ssh_key_file_location}}/{{item.name}}" mode="{{item.mode}}" |
| 56 | with_items: |
| 57 | - { "name": "cord_rsa", "mode": "0644" } |
| 58 | - { "name": "cord_rsa.pub", "mode": "0644" } |