diff options
author | binary <me@rgoncalves.se> | 2020-11-07 20:38:07 +0100 |
---|---|---|
committer | binary <me@rgoncalves.se> | 2020-11-07 20:38:07 +0100 |
commit | 352c98322771af117a85904d580e1c062062d634 (patch) | |
tree | d3bca9d27d6ee5d678264d83fc22030d274f30bf /roles/vmm/tasks/boot_alpine.yml | |
parent | 282be811d2ac07a76d56ac066df5bf33d748bd64 (diff) | |
download | infrastructure-352c98322771af117a85904d580e1c062062d634.tar.gz |
Refactor vmm role with automation
Diffstat (limited to 'roles/vmm/tasks/boot_alpine.yml')
-rw-r--r-- | roles/vmm/tasks/boot_alpine.yml | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/roles/vmm/tasks/boot_alpine.yml b/roles/vmm/tasks/boot_alpine.yml new file mode 100644 index 0000000..da4e91e --- /dev/null +++ b/roles/vmm/tasks/boot_alpine.yml @@ -0,0 +1,43 @@ + +# vmm ~~ tasks/boot_alpine.yml +# Boot an alpine image and init its installation set. +# Required : +# - guest : vm to be be bootup and initialized + +--- + +- name: Check arguments + fail: + msg: "arguments : guest" + when: guest is not defined + +- set_fact: + iso: "{{ hostvars[guest].iso }}" + disk_file : "{{ vmm.disk.dir }}/{{ guest }}.{{ vmm.disk.format }}" + +- include: set_facts.yml + +- name: Start vm + shell: | + vmctl stop dummy + sleep 2 + vmctl start -d {{ iso_latest | quote }} \ + -d {{ disk_file | quote }} \ + -n {{ vmm.config.switch.name | quote }} \ + -m {{ hostvars[guest].memory | quote }} dummy + + sleep 2 + tty=$(vmctl show | grep dummy | tr -s " " " " | cut -d " " -f 7) + sleep 20 + + cat << EOF > /dev/${tty} + echo "mkdir /root/.ssh" + echo "echo $(cat /root/.ssh/authorized_keys) > /root/.ssh/authorized_keys" > /dev/ttyp1 + echo "apk add openssh ; rc-update add sshd ; /etc/init.d/sshd start" /dev/${tty} + EOF + + exit 0 + + args: + executable: /bin/sh + |