Merge "bifrost-configdrives-dynamic: automatically find ed25519 SSH keys"

This commit is contained in:
Zuul 2020-09-29 17:30:27 +00:00 committed by Gerrit Code Review
commit dc4b453456
2 changed files with 28 additions and 14 deletions

View File

@ -6,7 +6,7 @@
write_interfaces_file: false
http_boot_folder: /httpboot
# Default location to the ssh public key for the user operating Bifrost.
ssh_public_key_path: "{{ lookup('env', 'HOME') }}/.ssh/id_rsa.pub"
#ssh_public_key_path: "/path/to/id_rsa.pub"
# Default interface name
# TODO(TheJulia): Remove this default.

View File

@ -12,18 +12,32 @@
# See the License for the specific language governing permissions and
# limitations under the License.
---
- name: "Defined ssh_public_key_path - Check to see if there is a file where the ssh_public_key_path is defined"
stat:
path: "{{ ssh_public_key_path }}"
register: test_ssh_public_key_path
when: ssh_public_key_path is defined
- block:
- name: "Find a suitable SSH public key"
set_fact:
ssh_public_key_path: "{{ item }}"
with_first_found:
- "{{ lookup('env', 'HOME') }}/.ssh/id_rsa.pub"
- "{{ lookup('env', 'HOME') }}/.ssh/id_ed25519.pub"
when: ssh_public_key_path is undefined
ignore_errors: yes
- name: "Error if ssh_public_key_path cannot be detected"
fail:
msg: "ssh_public_key_path and cannot be guessed from ~/.ssh"
when: ssh_public_key_path is undefined
- name: "Check to see if there is a file where the ssh_public_key_path is defined"
stat:
path: "{{ ssh_public_key_path }}"
register: test_ssh_public_key_path
- name: "Error if ssh_public_key_path is not valid"
fail:
msg: "ssh_public_key_path {{ ssh_public_key_path }} was not found"
when: not test_ssh_public_key_path.stat.exists
delegate_to: localhost
- name: "Defined ssh_public_key_path - Error if ssh_public_key_path is not valid"
fail:
msg: "ssh_public_key_path is not valid."
when: not test_ssh_public_key_path.stat.exists
delegate_to: localhost
- name: "Defined ssh_public_key_path - Read SSH public key in"
set_fact: ssh_public_key="{{ lookup('file', ssh_public_key_path ) }}"
- name: "Read SSH public key in ssh_public_key"
set_fact:
ssh_public_key: "{{ lookup('file', ssh_public_key_path ) }}"