Skip to content

Commit

Permalink
Merge pull request #448 from redhatci/add_ssh_keys_day1
Browse files Browse the repository at this point in the history
expand installer template to set extra SSH pub keys
  • Loading branch information
manurodriguez authored Oct 3, 2024
2 parents a9e4db3 + 13cee9f commit 1c96f44
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion roles/installer/tasks/25_create-install-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

- name: Set Fact for the ssh key of {{ ansible_user }}
set_fact:
key: "{{ sshkey['content'] | b64decode }}"
key: "{{ sshkey['content'] | b64decode | trim }}"
tags: installconfig

- name: Generate install-config.yaml
Expand Down
8 changes: 7 additions & 1 deletion roles/installer/templates/install-config-virtualmedia.j2
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ platform:
{% endfor %}
{% endif %}
pullSecret: '{{ pullsecret }}'
sshKey: '{{ key }}'
sshKey: |-
{{ key }}
{% if ssh_extra_keys_paths is defined and ssh_extra_keys_paths|length %}
{% for ssh_key_path in ssh_extra_keys_paths %}
{{ lookup('file', ssh_key_path | regex_replace('~', lookup('env', 'HOME'))) }}
{% endfor %}
{% endif %}
{% if install_config_appends is defined and install_config_appends|length %}
{{ install_config_appends }}
{% endif %}
8 changes: 7 additions & 1 deletion roles/installer/templates/install-config.j2
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,13 @@ platform:
{% endfor %}
{% endif %}
pullSecret: '{{ pullsecret }}'
sshKey: '{{ key }}'
sshKey: |-
{{ key }}
{% if ssh_extra_keys_paths is defined and ssh_extra_keys_paths|length %}
{% for ssh_key_path in ssh_extra_keys_paths %}
{{ lookup('file', ssh_key_path | regex_replace('~', lookup('env', 'HOME'))) }}
{% endfor %}
{% endif %}
{% if install_config_appends is defined and install_config_appends|length %}
{{ install_config_appends }}
{% endif %}
23 changes: 23 additions & 0 deletions roles/node_prep/tasks/10_validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,26 @@
tags:
- always
- validation

- name: Check if ssh_extra_keys_paths is defined and paths exist
when:
- ssh_extra_keys_paths is defined
- ssh_extra_keys_paths | length > 0
tags:
- always
- validation
block:
- name: Check if SSH keys exist
ansible.builtin.stat:
path: "{{ item }}"
loop: "{{ ssh_extra_keys_paths }}"
register: _np_ssh_path

- name: Fail if any ssh path does not exist
ansible.builtin.fail:
msg: "SSH public key {{ key.item }} file does not exist"
when: not key.stat.exists
loop: "{{ _np_ssh_path.results }}"
loop_control:
loop_var: key
label: "{{ key.item }}"

0 comments on commit 1c96f44

Please sign in to comment.