summaryrefslogtreecommitdiff
path: root/roles/raspios/image/tasks/main.yml
blob: 86373da63817c0b6cf9041a83f8c1291de45471a (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
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
70
71
---
- name: fetch base image
  run_once: true
  import_tasks: fetch.yml

- name: build the image
  block:
  - name: create the output directory for built images
    file:
      path: "{{ raspios_output_dir }}"
      state: directory

  - name: Create temporary build directory
    tempfile:
      state: directory
    register: tmpdir

  - name: extract image
    environment: ### TODO: remove once this lands in ansible: https://github.com/ansible/ansible/pull/76542
      LANGUAGE: en_US.utf8
    unarchive:
      src: "{{ raspios_download_dir }}/{{ raspios_download_image_base_name }}.zip"
      remote_src: yes
      dest: "{{ tmpdir.path }}"

  - name: read partition layout from image
    command: "sfdisk -q -r -J '{{ tmpdir.path }}/{{ raspios_download_image_base_name }}.img'"
    register: sfdisk_result

  - debug:
      var: sfdisk_result.stdout | from_json

  ## TODO:
  # udisksctl loop-setup -o {{ partitions[1].start * 512 }} -s {{ partitions[1].start * 512 }} -f '{{ tmpdir.path }}/{{ raspios_download_image_base_name }}.img'
  # udisksctl mount -b /dev/loop???
  #
  # do customizations.... (needs root?)

  - name: copy newly built raspios image
    copy:
      src: "{{ tmpdir.path }}/{{ raspios_download_image_base_name }}.img"
      dest: "{{ raspios_output_dir }}/{{ raspios_output_image_base_name }}.img"

  - name: set output image names
    set_fact:
      output_images:
      - "{{ raspios_output_dir }}/{{ raspios_output_image_base_name }}.img"

  always:
  - name: save stdout build-log to output directory
    when: raspios_build is defined
    copy:
      content: "{{ raspios_build.stdout }}\n"
      dest: "{{ raspios_output_dir }}/build-stdout.log"

  - name: save stderr build-log to output directory
    when: raspios_build is defined
    copy:
      content: "{{ raspios_build.stderr }}\n"
      dest: "{{ raspios_output_dir }}/build-stderr.log"

  - name: delete the temporary build directory
    when: not raspios_keep_temporary_build_dir
    file:
      path: "{{ tmpdir.path }}"
      state: absent

  - name: print temporary build directory information
    when: raspios_keep_temporary_build_dir
    debug:
      msg: "The temporary build directory has not been deleted, the path to the directory is: {{ tmpdir.path }}"