| # Copyright (c) 2023 VEXXHOST, 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: Generate public key for SSH private key |
| become: false |
| delegate_to: localhost |
| block: |
| - name: Generate temporary file for SSH public key |
| check_mode: false |
| changed_when: false |
| ansible.builtin.tempfile: |
| state: file |
| prefix: nova_ssh_key_ |
| register: _nova_ssh_key_tempfile |
| # NOTE(mnaser): It's important to add a trailing newline at the end of this |
| # string or else `ssh-keygen` will not be happy. |
| - name: Write contents of current private SSH key |
| check_mode: false |
| changed_when: false |
| ansible.builtin.copy: |
| dest: "{{ _nova_ssh_key_tempfile.path }}" |
| content: "{{ nova_ssh_key }}\n" |
| mode: "0600" |
| - name: Generate public key for SSH private key |
| changed_when: false |
| community.crypto.openssh_keypair: |
| path: "{{ _nova_ssh_key_tempfile.path }}" |
| regenerate: never |
| register: _nova_ssh_publickey |
| always: |
| - name: Delete temporary file for public SSH key |
| check_mode: false |
| changed_when: false |
| ansible.builtin.file: |
| path: "{{ _nova_ssh_key_tempfile.path }}" |
| state: absent |