zuul-jobs/roles/add-sshkey/tasks/main.yaml
Haikel Guemar 54bf1abaa4 Add-sshkey: ensure that ssh home directory exists
Some images might not have pre-created that directory, hence failing the task.
This simple step will prevent that.

Change-Id: Id2b63e84ef047f02127772c4d45b55ec360436f8
2020-09-01 14:43:15 +02:00

26 lines
679 B
YAML

- name: Ensure that ssh home directory exists
file:
path: "~/.ssh"
state: directory
mode: 0700
- name: Write out ssh key
copy:
dest: "~/.ssh/id_rsa"
content: "{{ ssh_key.ssh_private_key }}"
mode: 0600
# To almost everyone's surprise, if your pub key is different than
# your private, the private won't work. But it's okay for it to be
# absent.
- name: Delete ssh pub key if it exists
file:
path: "~/.ssh/id_rsa.pub"
state: absent
- name: Add host key information to known hosts
known_hosts:
name: "{{ ssh_key.fqdn }}"
key: "{{ ssh_key.ssh_known_hosts }}"
when: ssh_key.ssh_known_hosts is defined and ssh_key.fqdn is defined