bifrost/playbooks/roles/bifrost-ironic-install/ssh_public_key_path.yaml
Dmitry Tantsur b604f66e38 Allow inserting SSH public key for dynamic-login
Change-Id: I8b54030ef598c5860cd8d9929e9b58487f915fb1
2020-11-23 17:50:32 +01:00

44 lines
1.6 KiB
YAML

# Copyright (c) 2015 Hewlett-Packard Development Company, L.P.
#
# 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.
---
- 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: "Read SSH public key in ssh_public_key"
set_fact:
ssh_public_key: "{{ lookup('file', ssh_public_key_path, lstrip=True, rstrip=True) }}"