sidn-lxd-ansible-demo/roles/lxd_container/tasks/ansible_ssh_key.yml

31 lines
1.1 KiB
YAML

---
- name: "Copy ssh key installation script to the LXD host"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
copy:
src: /root/.ssh/install_ansible_ssh_key
dest: /root/.ssh/install_ansible_ssh_key
owner: root
group: root
mode: 755
# when: vars.group != "ansible" ... no idea why I did this. Old method maybe.
- name: "Install ssh key installation script on the LXD container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc file push /root/.ssh/install_ansible_ssh_key
{{ inventory_hostname }}/root/.ssh/install_ansible_ssh_key
- name: "Execute ssh key installation script on the LXD container"
delegate_to: "{{ hostvars[inventory_hostname].lxd_host }}"
shell: >-
lxc exec {{ inventory_hostname }} /root/.ssh/install_ansible_ssh_key
- name: "Add the LXD container host key to the ansible known hosts"
local_action: >-
command /etc/ansible/bin/add_ssh_known_host
{{ vars.network[segment.mgmt.network].address }}
/root/.ssh/id_ansible@{{ software.environment }}
- name: "Test if ansible can now use the ssh connection"
ping: