Tasks
main.yml
Synopsis: Main task.
Import tasks if enabled.
1---
2# tasks for freebsd_custom_image
3
4- name: Import debug.yml
5 ansible.builtin.import_tasks: debug.yml
6 when: cimage_debug | bool
7 tags: cimage_debug
8
9- name: Import sanity.yml
10 ansible.builtin.import_tasks: sanity.yml
11 when: cimage_sanity | bool
12 tags: cimage_sanity
13
14- name: Import download.yml
15 ansible.builtin.import_tasks: download.yml
16 when: cimage_download | bool
17 tags: cimage_download
18
19- name: Import unpack.yml
20 ansible.builtin.import_tasks: unpack.yml
21 when: cimage_unpack | bool
22 tags: cimage_unpack
23
24- name: Import mount.yml
25 ansible.builtin.import_tasks: mount.yml
26 when: cimage_mount | bool
27 tags: cimage_mount
28
29- name: Import packages.yml
30 ansible.builtin.import_tasks: packages.yml
31 when: cimage_install | bool
32 tags: cimage_packages
33
34- name: Import customize.yml
35 ansible.builtin.import_tasks: customize.yml
36 tags: cimage_customize
37
38- name: Import umount.yml
39 ansible.builtin.import_tasks: umount.yml
40 when: cimage_umount | bool
41 tags: cimage_umount
42
43# EOF
debug.yml
Synopsis: Configure debug
Description of the task.
1---
2- name: "Debug cimage_debug={{ cimage_debug }}"
3 vars:
4 msg: |-
5 cimage_role_version: {{ cimage_role_version }}
6 ansible_role_name: {{ ansible_role_name }}
7 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 ansible_facts.architecture: {{ ansible_facts.architecture }}
9 ansible_facts.os_family: {{ ansible_facts.os_family }}
10 ansible_facts.distribution: {{ ansible_facts.distribution }}
11 ansible_facts.distribution_major_version: {{ ansible_facts.distribution_major_version }}
12 ansible_facts.distribution_version: {{ ansible_facts.distribution_version }}
13 ansible_facts.distribution_release: {{ ansible_facts.distribution_release }}
14 ansible_facts.python_version: {{ ansible_facts.python_version }}
15 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16 cimage_sanity: {{ cimage_sanity }}
17 cimage_sanity_quiet: {{ cimage_sanity_quiet }}
18 cimage_download: {{ cimage_download }}
19 cimage_unpack: {{ cimage_unpack }}
20 cimage_mount: {{ cimage_mount }}
21 cimage_install: {{ cimage_install }}
22 cimage_umount: {{ cimage_umount }}
23 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
24 cimage_get_images: {{ cimage_get_images }}
25 cimage_get_checksums: {{ cimage_get_checksums }}
26 cimage_dir: {{ cimage_dir }}
27 cimage_owner: {{ cimage_owner | d('UNDEFINED') }}
28 cimage_group: {{ cimage_group | d('UNDEFINED') }}
29 cimage_mode: {{ cimage_mode | d('UNDEFINED') }}
30 cimage_mode_dir: {{ cimage_mode_dir | d('UNDEFINED') }}
31 cimage_download_images:
32 {{ cimage_download_images | to_nice_yaml(indent=2) | indent(2) }}
33 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
34 cimage_unpack_cmd:
35 {{ cimage_unpack_cmd | to_nice_yaml(indent=2) | indent(2) }}
36 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37 cimage_mount_path: {{ cimage_mount_path }}
38 cimage_mount_file: {{ cimage_mount_file }}
39 cimage_mount_mode: {{ cimage_mount_mode }}
40 cimage_mount_points_create: {{ cimage_mount_points_create }}
41 cimage_mount_points:
42 {{ cimage_mount_points | to_yaml(indent=2) | indent(2) }}
43 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44 freebsd_install_retries: {{ freebsd_install_retries }}
45 freebsd_install_delay: {{ freebsd_install_delay }}
46 cimage_pkgng_rootdir: {{ cimage_pkgng_rootdir }}
47 cimage_pkgng_use_globs: {{ cimage_pkgng_use_globs }}
48 cimage_pkgng_chroot: {{ cimage_pkgng_chroot | d('UNDEFINED') }}
49 cimage_pkgng_cached: {{ cimage_pkgng_cached | d('UNDEFINED') }}
50 cimage_pkgng_ignore_osver: {{ cimage_pkgng_ignore_osver | d('UNDEFINED') }}
51 cimage_pkgng_pkgsite: {{ cimage_pkgng_pkgsite | d('UNDEFINED') }}
52 cimage_packages:
53 {{ cimage_packages | to_nice_yaml(indent=2) | indent(2) }}
54 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55 cimage_customize:
56 {{ cimage_packages | to_yaml(indent=2) | indent(2) }}
57 ansible.builtin.debug:
58 msg: "{{ '{}'.format(msg) }}"
59
60# EOF
packages.yml
Synopsis: Configure packages
Description of the task.
1---
2- name: "Package: Install packages."
3 register: result
4 community.general.pkgng:
5 name: "{{ cimage_packages }}"
6 rootdir: "{{ cimage_pkgng_rootdir }}"
7 use_globs: "{{ cimage_pkgng_use_globs }}"
8 chroot: "{{ cimage_pkgng_chroot | d(omit) }}"
9 cached: "{{ cimage_pkgng_cached | d(omit) }}"
10 ignore_osver: "{{ cimage_pkgng_ignore_osver | d(omit) }}"
11 pkgsite: "{{ cimage_pkgng_pkgsite | d(omit) }}"
12 retries: "{{ freebsd_install_retries }}"
13 until: result is succeeded
14 delay: "{{ freebsd_install_delay }}"
15
16# EOF
sanity.yml
Synopsis: Configure sanity
Description of the task.
1---
2- name: "Sanity: Only FreeBSD family supported"
3 ansible.builtin.assert:
4 that: ansible_facts.os_family == 'FreeBSD'
5 fail_msg: "[ERR] Only FreeBSD family supported."
6 quiet: "{{ cimage_sanity_quiet | bool }}"
7
8- name: "Sanity: Stat image"
9 register: st
10 ansible.builtin.stat:
11 path: "{{ cimage_dir }}/{{ cimage_mount_file }}"
12
13- name: "Sanity: Image exists"
14 ansible.builtin.assert:
15 that: st.stat.exists
16 fail_msg: "[ERR] {{ cimage_dir }}/{{ cimage_mount_file }} does not exist."
17 quiet: "{{ cimage_sanity_quiet | bool }}"
18
19- name: "Sanity: Image is regular file or link"
20 ansible.builtin.assert:
21 that: st.stat.isreg or st.stat.islnk
22 fail_msg: "[ERR] {{ cimage_dir }}/{{ cimage_mount_file }} is neither a file nor symbolic link."
23 quiet: "{{ cimage_sanity_quiet | bool }}"
24
25- name: "Sanity: Image is not writable"
26 ansible.builtin.assert:
27 that: st.stat.writeable
28 fail_msg: "[ERR] {{ cimage_dir }}/{{ cimage_mount_file }} is not writable."
29 quiet: "{{ cimage_sanity_quiet | bool }}"
30
31# EOF
download.yml
Synopsis: Configure download
Description of the task.
1---
2- name: "Download: Debug cimage_debug={{ cimage_debug }}"
3 when: cimage_debug | bool
4 vars:
5 msg: |-
6 cimage_dir: {{ cimage_dir }}
7 cimage_owner: {{ cimage_owner | d('UNDEFINED') }}
8 cimage_group: {{ cimage_group | d('UNDEFINED') }}
9 cimage_mode: {{ cimage_mode | d('UNDEFINED') }}
10 cimage_mode_dir: {{ cimage_mode_dir | d('UNDEFINED') }}
11 cimage_get_checksums: {{ cimage_get_checksums }}
12 cimage_get_images: {{ cimage_get_images }}
13 cimage_download_images:
14 {{ cimage_download_images | to_nice_yaml(indent=2) | indent(2) }}
15 ansible.builtin.debug:
16 msg: "{{ '{}'.format(msg) }}"
17
18- name: "Download: Create directory {{ cimage_dir }}"
19 ansible.builtin.file:
20 state: directory
21 path: "{{ cimage_dir }}"
22 owner: "{{ cimage_owner | d(omit) }}"
23 group: "{{ cimage_group | d(omit) }}"
24 mode: "{{ cimage_mode_dir | d(omit) }}"
25
26- name: Checksums
27 when: cimage_get_checksums | bool
28 block:
29
30 - name: "Download: Get checksums"
31 environment:
32 CRYPTOGRAPHY_OPENSSL_NO_LEGACY: '1'
33 ansible.builtin.get_url:
34 url: "{{ [item.site, item.checksum] | community.general.path_join }}"
35 dest: "{{ [cimage_dir, item.checksum] | community.general.path_join }}"
36 owner: "{{ cimage_owner | d(omit) }}"
37 group: "{{ cimage_group | d(omit) }}"
38 mode: "{{ cimage_mode | d(omit) }}"
39 loop: "{{ cimage_download_images }}"
40 loop_control:
41 label: "{{ item.checksum }}"
42
43 - name: "Download: Read checksums"
44 changed_when: false
45 check_mode: false
46 ansible.builtin.command:
47 cmd: >
48 cat {{ [cimage_dir, item.checksum] | community.general.path_join }}
49 register: cresult
50 loop: "{{ cimage_download_images }}"
51 loop_control:
52 label: "{{ item.checksum }}"
53
54 - name: "Download: Debug checksums cimage_debug={{ cimage_debug }}"
55 when:
56 - cimage_debug | bool
57 - cresult.results[ansible_loop.index0].stdout is defined
58 vars:
59 algorithm: "{{ cresult.results[ansible_loop.index0].stdout | split | first | lower }}"
60 checksum: "{{ cresult.results[ansible_loop.index0].stdout | split | last }}"
61 ansible.builtin.debug:
62 msg: "{{ algorithm }}:{{ checksum }}"
63 loop: "{{ cimage_download_images }}"
64 loop_control:
65 label: "{{ item.image }}"
66 extended: true
67
68- name: Images
69 when: cimage_get_images | bool
70 block:
71
72 - name: "Download: Get images"
73 when: cresult.results[ansible_loop.index0].stdout is defined
74 environment:
75 CRYPTOGRAPHY_OPENSSL_NO_LEGACY: '1'
76 vars:
77 algorithm: "{{ cresult.results[ansible_loop.index0].stdout.split() | first | lower }}"
78 checksum: "{{ cresult.results[ansible_loop.index0].stdout.split() | last }}"
79 ansible.builtin.get_url:
80 url: "{{ [item.site, item.image] | community.general.path_join }}"
81 dest: "{{ [cimage_dir, item.image] | community.general.path_join }}"
82 checksum: "{{ algorithm }}:{{ checksum }}"
83 owner: "{{ cimage_owner | d(omit) }}"
84 group: "{{ cimage_group | d(omit) }}"
85 mode: "{{ cimage_mode | d(omit) }}"
86 register: out
87 loop: "{{ cimage_download_images }}"
88 loop_control:
89 label: "{{ item.image }}"
90 extended: true
91
92 - name: "Download: Debug images cimage_debug={{ cimage_debug }}"
93 when: cimage_debug | bool
94 ansible.builtin.debug:
95 var: out
96
97# EOF
mount.yml
Synopsis: Configure mount
Description of the task.
1---
2- name: "Mount: Debug cimage_debug={{ cimage_debug }}"
3 when: cimage_debug | bool
4 vars:
5 msg: |-
6 cimage_dir: {{ cimage_dir }}
7 cimage_mount_file: {{ cimage_mount_file }}
8 cimage_mount_mode: {{ cimage_mount_mode }}
9 cimage_mount_points_create: {{ cimage_mount_points_create }}
10 cimage_mount_points:
11 {{ cimage_mount_points | to_yaml(indent=2) | indent(2) }}
12 ansible.builtin.debug:
13 msg: "{{ '{}'.format(msg) }}"
14
15- name: "Mount: Create mount points"
16 when: cimage_mount_points_create | bool # Note 2.
17 tags: cimage_mount_points
18 ansible.builtin.file:
19 state: directory
20 path: "{{ item.mountpoint }}"
21 mode: "{{ cimage_mount_mode }}"
22 loop: "{{ cimage_mount_points }}"
23
24- name: "Mount: Attach memory disk" # noqa: var-naming[no-role-prefix]
25 vars:
26 al_mdconfig_file: "{{ cimage_dir }}/{{ cimage_mount_file }}"
27 ansible.builtin.include_role:
28 name: "{{ cimage_ansible_lib[ansible_role_name] }}"
29 tasks_from: al_mdconfig.yml
30
31- name: "Mount: Set variable cimage_mount_dev"
32 tags: cimage_mdconfig
33 ansible.builtin.set_fact:
34 cimage_mount_dev: md{{ al_mdconfig_devs[my_file]['unit'] | d('UNDEFINED') }}
35 vars:
36 my_file: "{{ cimage_dir }}/{{ cimage_mount_file }}"
37
38- name: "Mount: Debug {{ cimage_dir ~ '/' ~ cimage_mount_file }}"
39 when: cimage_debug | bool
40 tags: cimage_mdconfig
41 ansible.builtin.debug:
42 msg: "Mounted at: {{ cimage_mount_dev }}"
43
44- name: "Mount: Mount partitions {{ cimage_mount_dev }}"
45 register: result
46 ansible.posix.mount:
47 src: /dev/{{ cimage_mount_dev }}{{ item.partition }}
48 path: "{{ item.mountpoint }}" # Note 2.
49 fstype: "{{ item.fstype }}"
50 state: mounted
51 fstab: /tmp/tmp.fstab # Note 1.
52 loop: "{{ cimage_mount_points }}"
53
54- name: "Mount: Debug mount results cimage_debug={{ cimage_debug }}"
55 when: cimage_debug | bool
56 ansible.builtin.debug:
57 var: result
58
59# Notes
60#
61# Note 1: It's not possible to mount a device without touching fstab. Temporary fstab is a
62# workaround.
63# See https://github.com/ansible-collections/ansible.posix/issues/84#issuecomment-742420345
64## Note 2: Ansible module *mount* will create/remove non-existent mountpoint
65
66# EOF
umount.yml
Synopsis: Configure umount
Description of the task.
1---
2- name: "Umount: Debug cimage_debug={{ cimage_debug }}"
3 when: cimage_debug | bool
4 vars:
5 msg: |-
6 cimage_mount_points:
7 {{ cimage_mount_points | to_yaml(indent=2) | indent(2) }}
8 ansible.builtin.debug:
9 msg: "{{ '{}'.format(msg) }}"
10
11- name: "Umount: Unmount"
12 register: result
13 ansible.posix.mount:
14 path: "{{ item.mountpoint }}"
15 state: unmounted
16 fstab: /tmp/tmp.fstab # Note 1.
17 loop: "{{ cimage_mount_points }}"
18 loop_control:
19 label: "{{ item.mountpoint }}"
20
21- name: "Umount: Debug unmount results cimage_debug={{ cimage_debug }}"
22 when: cimage_debug | bool
23 ansible.builtin.debug:
24 var: result
25
26- name: "Umount: Detach memory disk" # noqa: var-naming[no-role-prefix]
27 vars:
28 al_mdconfig_file: "{{ cimage_dir }}/{{ cimage_mount_file }}"
29 al_mdconfig_state: absent
30 ansible.builtin.include_role:
31 name: "{{ cimage_ansible_lib[ansible_role_name] }}"
32 tasks_from: al_mdconfig.yml
33
34- name: "Umount: Debug detach memory disk cimage_debug={{ cimage_debug }}"
35 when: cimage_debug | bool
36 ansible.builtin.debug:
37 var: al_mdconfig_devs
38
39# Notes
40#
41# Note 1: It's not possible to mount a device without touching fstab. Temporary fstab is a
42# workaround.
43# See https://github.com/ansible-collections/ansible.posix/issues/84#issuecomment-742420345
44
45# EOF
customize.yml
Synopsis: Configure customize
Description of the task.
1---
2- name: "Customize: Debug cimage_debug={{ cimage_debug }}"
3 when: cimage_debug | bool
4 ansible.builtin.debug:
5 var:
6 cimage_customize
7
8- name: Customize image.
9 ansible.builtin.include_tasks: "fn/{{ customize_item }}.yml"
10 loop: "{{ cimage_customize | dict2items | selectattr('value') | map(attribute='key') }}"
11 loop_control:
12 loop_var: customize_item
13
14# EOF
loaderconf.yml
Synopsis: Configure loaderconf
Description of the task.
1---
2- name: "Loaderconf: Debug cimage_debug={{ cimage_debug }}"
3 when: cimage_debug | bool
4 vars:
5 msg: |-
6 cimage_loaderconf_backup: {{ cimage_loaderconf_backup }}
7 cimage_loaderconf_modules:
8 {{ cimage_loaderconf_modules | to_yaml(indent=2) | indent(2) }}
9 cimage_loaderconf_data:
10 {{ cimage_loaderconf_data | to_nice_yaml(indent=2) | indent(2) }}
11 cimage_loaderconf_sysctl:
12 {{ cimage_loaderconf_sysctl | to_nice_yaml(indent=2) | indent(2) }}
13 ansible.builtin.debug:
14 msg: "{{ '{}'.format(msg) }}"
15
16- name: "Loaderconf: Configure {{ cimage_mount_path ~ '/boot/loader.conf' }}"
17 ansible.builtin.template:
18 src: loader.conf.j2
19 dest: "{{ cimage_mount_path }}/boot/loader.conf"
20 owner: root
21 group: wheel
22 mode: "0644"
23 backup: "{{ cimage_loaderconf_backup }}"
24
25# EOF
rcconf.yml
Synopsis: Configure rcconf
Description of the task.
1---
2- name: "Rcconf: Debug cimage_debug={{ cimage_debug }}"
3 when: cimage_debug | bool
4 ansible.builtin.debug:
5 var: cimage_rcconf_data
6
7- name: "Rcconf: Configure {{ cimage_mount_path ~ '/etc/rc.conf' }}"
8 community.general.sysrc:
9 path: "{{ cimage_mount_path }}/etc/rc.conf"
10 name: "{{ item.key }}"
11 value: "{{ item.value }}"
12 loop: "{{ cimage_rcconf_data }}"
13
14# EOF
wpasupconf.yml
Synopsis: Configure wpasupconf
Description of the task.
1---
2- name: "Wpasupconf: Debug cimage_debug={{ cimage_debug }}"
3 when: cimage_debug | bool
4 vars:
5 msg: |-
6 cimage_wpasupconf_backup: {{ cimage_wpasupconf_backup }}
7 cimage_wpasupconf_template: {{ cimage_wpasupconf_template }}
8 cimage_wpasupconf_file: {{ cimage_wpasupconf_file }}
9 cimage_wpasupconf_owner: {{ cimage_wpasupconf_owner }}
10 cimage_wpasupconf_group: {{ cimage_wpasupconf_group }}
11 cimage_wpasupconf_mode: {{ cimage_wpasupconf_mode }}
12 cimage_wpasupconf_global:
13 {{ cimage_wpasupconf_global | to_yaml(indent=2) | indent(2) }}
14 {% if cimage_debug_classified %}
15 cimage_wpasupconf_data:
16 {{ cimage_wpasupconf_data | to_yaml(indent=2) | indent(2) }}
17 {% endif %}
18 cimage_wpasupconf_link: {{ cimage_wpasupconf_link }}
19 cimage_wpasupconf_link_dev: {{ cimage_wpasupconf_link_dev }}
20 ansible.builtin.debug:
21 msg: "{{ '{}'.format(msg) }}"
22
23- name: "Wpasupconf: Configure {{ cimage_mount_path ~ '/etc/wpasupplicant.conf' }}"
24 ansible.builtin.template:
25 src: "{{ cimage_wpasupconf_template }}"
26 dest: "{{ cimage_mount_path }}/{{ cimage_wpasupconf_file }}.{{ item.dev }}"
27 owner: "{{ cimage_wpasupconf_owner }}"
28 group: "{{ cimage_wpasupconf_group }}"
29 mode: "{{ cimage_wpasupconf_mode }}"
30 backup: "{{ cimage_wpasupconf_backup }}"
31 loop: "{{ cimage_wpasupconf_data }}"
32 loop_control:
33 label: "{{ item.dev }}"
34
35- name: "Wpasupconf: Link to {{ cimage_wpasupconf_file ~ '.' ~ cimage_wpasupconf_link_dev }}"
36 when: cimage_wpasupconf_link | bool
37 ansible.builtin.file:
38 state: link
39 src: wpa_supplicant.conf.{{ cimage_wpasupconf_link_dev }}
40 dest: "{{ cimage_mount_path }}/{{ cimage_wpasupconf_file }}"
41 force: true
42
43# EOF