summaryrefslogtreecommitdiff
path: root/roles/vmware/tasks/convert.yml
blob: 39f4e8b9394e3bda00edf7bf21dc4899160d2ee2 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
- name: Convert raw to vmdk
  command: qemu-img convert -f raw "{{ vyos_raw_img }}" -O vmdk -o adapter_type=lsilogic "{{ vyos_vmware_tmp_vmdk }}"
- name: Fix vmdk with open-vmdk
  command: vmdk-convert "{{ vyos_vmware_tmp_vmdk }}" "{{ vyos_vmware_vmdk }}"
- name: Get vmdk_file_size
  shell: du --bytes "{{ vyos_vmware_vmdk }}" | cut -f1
  register: vmdk_file_size
- name: Get vmdk_populated_size
  shell: vmdk-convert -i "{{ vyos_vmware_vmdk }}"
  register: result
- name: Set vmdk_populated_size
  set_fact:
    vmdk_populated_size: "{{ (result.stdout | from_json).used }}"
- name: Generate OVF
  become: false
  template:
    src: templates/vyos_vmware_image.ovf.j2
    dest: "{{ vyos_vmware_ovf }}"
- name: Generate MF
  shell: openssl sha1 "{{ vyos_vmware_vmdk | basename }}" "{{ vyos_vmware_ovf | basename }}"
  args:
    chdir: /tmp
  register: result
- name: Create MF
  become: false
  copy:
    dest: "{{ vyos_vmware_mf }}"
    content: "{{ result.stdout }}"
- name: Create OVA without private key
  become: false
  archive:
    path:
      - "{{ vyos_vmware_ovf }}"
      - "{{ vyos_vmware_mf }}"
      - "{{ vyos_vmware_vmdk }}"
    dest: "{{ vyos_vmware_ova }}"
    format: tar
  when: vyos_vmware_private_key_path is not defined
- name: Sign MF
  shell: openssl dgst -sha256 -sign "{{ vyos_vmware_private_key_path }}" -hex "{{ vyos_vmware_mf | basename }}" | sed 's/^RSA-//'
  args:
    chdir: /tmp
  register: signature
  when: vyos_vmware_private_key_path is defined
- name: Get certificate
  shell: openssl x509 -in "{{ vyos_vmware_private_key_path }}"
  register: certificate
  when: vyos_vmware_private_key_path is defined
- name: Create cert file for OVA
  become: false
  copy:
    dest: "{{ vyos_vmware_cert }}"
    content: |
      {{ signature.stdout }}
      {{ certificate.stdout }}
- name: Create OVA with private key
  become: false
  archive:
    path:
      - "{{ vyos_vmware_ovf }}"
      - "{{ vyos_vmware_mf }}"
      - "{{ vyos_vmware_cert }}"
      - "{{ vyos_vmware_vmdk }}"
    dest: "{{ vyos_vmware_ova }}"
    format: tar
  when: vyos_vmware_private_key_path is defined
- name: Copy image
  become: false
  command: cp "{{ vyos_vmware_ova }}" .