bifrost-configdrives-dynamic: automatically find ed25519 SSH keys

Also make the SSH key detection code a bit more readable.

Change-Id: Ia365f75d7fac3d64d8dce898ca854149c0aeed6e
This commit is contained in:
Dmitry Tantsur 2020-09-18 13:14:42 +02:00
parent 3823944c76
commit d550a1f7c4
2 changed files with 28 additions and 14 deletions

View File

@ -6,7 +6,7 @@
write_interfaces_file: false write_interfaces_file: false
http_boot_folder: /httpboot http_boot_folder: /httpboot
# Default location to the ssh public key for the user operating Bifrost. # 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 # Default interface name
# TODO(TheJulia): Remove this default. # TODO(TheJulia): Remove this default.

View File

@ -12,18 +12,32 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # 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" - block:
stat: - name: "Find a suitable SSH public key"
path: "{{ ssh_public_key_path }}" set_fact:
register: test_ssh_public_key_path ssh_public_key_path: "{{ item }}"
when: ssh_public_key_path is defined 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 delegate_to: localhost
- name: "Defined ssh_public_key_path - Error if ssh_public_key_path is not valid" - name: "Read SSH public key in ssh_public_key"
fail: set_fact:
msg: "ssh_public_key_path is not valid." ssh_public_key: "{{ lookup('file', ssh_public_key_path ) }}"
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 ) }}"