diff options
author | binary <me@rgoncalves.se> | 2020-11-08 20:56:18 +0100 |
---|---|---|
committer | binary <me@rgoncalves.se> | 2020-11-08 20:56:18 +0100 |
commit | e15d9acbd07c1ecb6e6c6b24f547b60f7d92ebaf (patch) | |
tree | ef0130c97f594ca7d57676c9e1d027724211fba8 /roles/vmm/tasks | |
parent | 605d9efb0ad2734278d8bdb5f9e0862d8e0a1a7e (diff) | |
download | infrastructure-e15d9acbd07c1ecb6e6c6b24f547b60f7d92ebaf.tar.gz |
Add working script for ssh init on alpine vm
Diffstat (limited to 'roles/vmm/tasks')
-rw-r--r-- | roles/vmm/tasks/boot_alpine.yml | 43 | ||||
-rw-r--r-- | roles/vmm/tasks/generate_vmconf.yml | 21 | ||||
-rw-r--r-- | roles/vmm/tasks/init_hypervisor.yml | 1 | ||||
-rw-r--r-- | roles/vmm/tasks/init_vm.yml | 26 |
4 files changed, 44 insertions, 47 deletions
diff --git a/roles/vmm/tasks/boot_alpine.yml b/roles/vmm/tasks/boot_alpine.yml deleted file mode 100644 index da4e91e..0000000 --- a/roles/vmm/tasks/boot_alpine.yml +++ /dev/null @@ -1,43 +0,0 @@ - -# 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 - diff --git a/roles/vmm/tasks/generate_vmconf.yml b/roles/vmm/tasks/generate_vmconf.yml index c4e80d8..e8f8245 100644 --- a/roles/vmm/tasks/generate_vmconf.yml +++ b/roles/vmm/tasks/generate_vmconf.yml @@ -4,13 +4,26 @@ --- +- name: Start ip forwarding + shell: sysctl net.inet.ip{{ item }}.forwarding=1 + loop: + - "" + - "6" + +- name: Enable ip forwarding + lineinfile: + path: /etc/sysctl.conf + regexp: "^net.inet.ip{{ item }}.forwarding=" + line: "net.inet.ip{{ item }}.forwarding=1" + loop: + - "" + - "6" + - name: Create network switch - template: - src: templates/hostname.j2 - dest: "/etc/hostname.{{ vmm.switch.interface }}" + shell: echo "add {{ hypervisor.interface }}" > /etc/hostname.{{ vmm.switch.iface }} - name: Start network switch - shell: "sh /etc/netstart {{ vmm.switch.interface }}" + shell: "sh /etc/netstart {{ vmm.switch.iface }}" - name: Generate vmm configuration template: diff --git a/roles/vmm/tasks/init_hypervisor.yml b/roles/vmm/tasks/init_hypervisor.yml index c963bbb..b206279 100644 --- a/roles/vmm/tasks/init_hypervisor.yml +++ b/roles/vmm/tasks/init_hypervisor.yml @@ -10,3 +10,4 @@ - include: generate_vmconf.yml guest="{{ item }}" loop: "{{ hostvars[ansible_host] }}.vm.hosts" + diff --git a/roles/vmm/tasks/init_vm.yml b/roles/vmm/tasks/init_vm.yml new file mode 100644 index 0000000..4ded177 --- /dev/null +++ b/roles/vmm/tasks/init_vm.yml @@ -0,0 +1,26 @@ + +# vmm ~~ tasks/init_vm.yml + +--- + +- include_role: + name: serial + +- set_fact: + + +- name: Init vm via script + script: init_vm_serial.py \ + {{ guest }} \ + {{ hostvars[guest].ip.out }} \ + {{ hypervisor.gateway }} \ + {{ hypervisor.mask }} \ + {{ _i.dns[0] }} \ + "{{ lookup('file', inventory_dir + '/files/pubkeys/rgoncalves.pub') }}" + args: + executable: "/usr/local/bin/python3" + register: rg + +- name: Installation result + debug: + var: rg.stdout_lines |