aboutsummaryrefslogtreecommitdiffstats
path: root/roles/vmm/tasks/boot_alpine.yml
blob: da4e91edb515a6fb52d0adde006b6b75e437c7cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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

remember that computers suck.