Tasks

main.yml

Synopsis: Main task.

Import tasks if enabled.

[tasks/main.yml]

 1---
 2# tasks for freebsd_custom_image
 3
 4- name: Import debug.yml
 5  ansible.builtin.import_tasks: debug.yml
 6  when: bsd_cimage_debug | bool
 7  tags: bsd_cimage_debug
 8
 9- name: Import packages.yml
10  ansible.builtin.import_tasks: packages.yml
11  when: bsd_cimage_install | bool
12  tags: bsd_cimage_packages
13
14- name: Import sanity.yml
15  ansible.builtin.import_tasks: sanity.yml
16  when: bsd_cimage_sanity | bool
17  tags: [bsd_cimage_sanity, always]
18
19- name: Import download.yml
20  ansible.builtin.import_tasks: download.yml
21  tags: bsd_cimage_download
22
23- name: Import unpack.yml
24  ansible.builtin.import_tasks: unpack.yml
25  tags: bsd_cimage_unpack
26
27- name: Import mount.yml
28  ansible.builtin.import_tasks: mount.yml
29  when: bsd_cimage_mount | bool
30  tags: bsd_cimage_mount
31
32- name: Import customize.yml
33  ansible.builtin.import_tasks: customize.yml
34  tags: bsd_cimage_customize
35
36- name: Import umount.yml
37  ansible.builtin.import_tasks: umount.yml
38  when: bsd_cimage_umount | bool
39  tags: bsd_cimage_umount
40
41# EOF

debug.yml

Synopsis: Configure debug.

Description of the task.

[tasks/debug.yml]

 1---
 2- name: Debug
 3  vars:
 4    msg: |-
 5      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 6      ansible_architecture: {{ ansible_architecture }}
 7      ansible_os_family: {{ ansible_os_family }}
 8      ansible_distribution: {{ ansible_distribution }}
 9      ansible_distribution_major_version: {{ ansible_distribution_major_version }}
10      ansible_distribution_version: {{ ansible_distribution_version }}
11      ansible_distribution_release: {{ ansible_distribution_release }}
12      ansible_python_version: {{ ansible_python_version }}
13      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14      freebsd_install_method: {{ freebsd_install_method }}
15      freebsd_use_packages: {{ freebsd_use_packages }}
16      freebsd_install_retries: {{ freebsd_install_retries }}
17      freebsd_install_delay: {{ freebsd_install_delay }}
18      bsd_cimage_install: {{ bsd_cimage_install }}
19      bsd_cimage_packages:
20        {{ bsd_cimage_packages | to_nice_yaml(indent=2) | indent(2) }}
21      bsd_cimage_sanity: {{ bsd_cimage_sanity }}
22      bsd_cimage_mount: {{ bsd_cimage_mount }}
23      bsd_cimage_umount: {{ bsd_cimage_umount }}
24      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25      bsd_cimage_dir: {{ bsd_cimage_dir }}
26      bsd_cimage_owner: {{ bsd_cimage_owner | default('UNDEFINED') }}
27      bsd_cimage_group: {{ bsd_cimage_group | default('UNDEFINED') }}
28      bsd_cimage_mode: {{ bsd_cimage_mode | default('UNDEFINED') }}
29      bsd_cimage_download:
30        {{ bsd_cimage_download | to_nice_yaml(indent=2) | indent(2) }}
31      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32      bsd_cimage_mount_dir: {{ bsd_cimage_mount_dir }}
33      bsd_cimage_mount_file: {{ bsd_cimage_mount_file }}
34      bsd_cimage_mount_mode: {{ bsd_cimage_mount_mode }}
35      bsd_cimage_mount_points_create: {{ bsd_cimage_mount_points_create }}
36      bsd_cimage_mount_points:
37        {{ bsd_cimage_mount_points | to_yaml(indent=2) | indent(2) }}
38      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39      bsd_cimage_mount_path: {{ bsd_cimage_mount_path }}
40      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
41      bsd_cimage_loaderconf: {{ bsd_cimage_loaderconf }}
42      bsd_cimage_loaderconf_backup: {{ bsd_cimage_loaderconf_backup }}
43      bsd_cimage_loaderconf_modules:
44        {{ bsd_cimage_loaderconf_modules | to_yaml(indent=2) | indent(2) }}
45      bsd_cimage_loaderconf_data:
46        {{ bsd_cimage_loaderconf_data | to_nice_yaml(indent=2) | indent(2) }}
47      bsd_cimage_loaderconf_sysctl:
48        {{ bsd_cimage_loaderconf_sysctl | to_nice_yaml(indent=2) | indent(2) }}
49      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50      bsd_cimage_rcconf: {{ bsd_cimage_rcconf }}
51      bsd_cimage_rcconf_backup: {{ bsd_cimage_rcconf_backup }}
52      bsd_cimage_rcconf_data:
53        {{ bsd_cimage_rcconf_data | to_yaml(indent=2) | indent(2) }}
54      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55      bsd_cimage_wpasupconf: {{ bsd_cimage_wpasupconf }}
56      bsd_cimage_wpasupconf_backup: {{ bsd_cimage_wpasupconf_backup }}
57      bsd_cimage_wpasupconf_file: {{ bsd_cimage_wpasupconf_file }}
58      bsd_cimage_wpasupconf_owner: {{ bsd_cimage_wpasupconf_owner }}
59      bsd_cimage_wpasupconf_group: {{ bsd_cimage_wpasupconf_group }}
60      bsd_cimage_wpasupconf_mode: {{ bsd_cimage_wpasupconf_mode }}
61      bsd_cimage_wpasupconf_global:
62        {{ bsd_cimage_wpasupconf_global | to_nice_yaml(indent=2) | indent(2) }}
63      {% if bsd_cimage_debug_classified %}
64      bsd_cimage_wpasupconf_data:
65        {{ bsd_cimage_wpasupconf_data | to_nice_yaml(indent=2) | indent(2) }}
66      {% endif %}
67      bsd_cimage_wpasupconf_link: {{ bsd_cimage_wpasupconf_link }}
68      bsd_cimage_wpasupconf_link_dev: {{ bsd_cimage_wpasupconf_link_dev }}
69      - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70
71  ansible.builtin.debug:
72    msg: "{{ '{}'.format(msg) }}"
73
74# EOF

packages.yml

Synopsis: Configure packages.

Description of the task.

[tasks/packages.yml]

 1---
 2- name: "Package: Install packages."
 3  community.general.pkgng:
 4    name: "{{ bsd_cimage_packages }}"
 5  register: result
 6  retries: "{{ freebsd_install_retries }}"
 7  until: result is succeeded
 8  delay: "{{ freebsd_install_delay }}"
 9  when: freebsd_install_method == "packages"
10
11- name: "Packages: Install ports."
12  community.general.portinstall:
13    name: "{{ item }}"
14    use_packages: "{{ freebsd_use_packages }}"
15  loop: "{{ bsd_cimage_packages }}"
16  register: result
17  retries: "{{ freebsd_install_retries }}"
18  until: result is succeeded
19  delay: "{{ freebsd_install_delay }}"
20  when: freebsd_install_method == "ports"
21
22# EOF

sanity.yml

Synopsis: Configure sanity.

Description of the task.

[tasks/sanity.yml]

 1---
 2- name: "Sanity: Only FreeBSD family supported"
 3  ansible.builtin.assert:
 4    that: ansible_os_family == 'FreeBSD'
 5    fail_msg: "[ERR] Only FreeBSD family supported."
 6
 7- name: "Sanity: Stat image"
 8  ansible.builtin.stat:
 9    path: "{{ bsd_cimage_mount_dir }}/{{ bsd_cimage_mount_file }}"
10  register: st
11
12- name: "Sanity: Image exists"
13  ansible.builtin.assert:
14    that: st.stat.exists
15    fail_msg: "[ERR] {{ bsd_cimage_mount_dir }}/{{ bsd_cimage_mount_file }} does not exist."
16
17- name: "Sanity: Image is regular file or link"
18  ansible.builtin.assert:
19    that: st.stat.isreg or st.stat.islnk
20    fail_msg: "[ERR] {{ bsd_cimage_mount_dir }}/{{ bsd_cimage_mount_file }} is neither a file nor symbolic link."
21
22- name: "Sanity: Image is not writable"
23  ansible.builtin.assert:
24    that: st.stat.writeable
25    fail_msg: "[ERR] {{ bsd_cimage_mount_dir }}/{{ bsd_cimage_mount_file }} is not writable."
26
27# EOF

download.yml

Synopsis: Configure download.

Description of the task.

[tasks/download.yml]

 1---
 2- name: "Download: Debug"
 3  vars:
 4    msg: |-
 5      bsd_cimage_download:
 6        {{ bsd_cimage_download | to_nice_yaml(indent=2) | indent(2) }}
 7      bsd_cimage_dir: {{ bsd_cimage_dir }}
 8      bsd_cimage_owner: {{ bsd_cimage_owner | default('UNDEFINED') }}
 9      bsd_cimage_group: {{ bsd_cimage_group | default('UNDEFINED') }}
10      bsd_cimage_mode: {{ bsd_cimage_mode | default('UNDEFINED') }}
11      bsd_cimage_get_checksums: {{ bsd_cimage_get_checksums | default(true) }}
12      bsd_cimage_get_images: {{ bsd_cimage_get_images | default(true) }}
13  ansible.builtin.debug:
14    msg: "{{ '{}'.format(msg) }}"
15  when: bsd_cimage_debug | bool
16
17- name: "Download: Get checksums"
18  ansible.builtin.get_url:
19    url: "{{ [item.site, item.checksum] | community.general.path_join }}"
20    dest: "{{ [bsd_cimage_dir, item.checksum] | community.general.path_join }}"
21    owner: "{{ bsd_cimage_owner | d(omit) }}"
22    group: "{{ bsd_cimage_group | d(omit) }}"
23    mode: "{{ bsd_cimage_mode | d(omit) }}"
24  loop: "{{ bsd_cimage_download }}"
25  loop_control:
26    label: "{{ item.checksum }}"
27  when: bsd_cimage_get_checksums | d(true) | bool
28
29- name: "Download: Read checksums"
30  ansible.builtin.command:
31    cmd: >
32      cat {{ [bsd_cimage_dir, item.checksum] | community.general.path_join }}
33  register: cresult
34  loop: "{{ bsd_cimage_download }}"
35  loop_control:
36    label: "{{ item.checksum }}"
37  changed_when: false
38  check_mode: false
39
40- name: "Download: Debug checksums"
41  ansible.builtin.debug:
42    msg: "{{ algorithm }}:{{ checksum }}"
43  loop: "{{ bsd_cimage_download }}"
44  loop_control:
45    label: "{{ item.image }}"
46    extended: true
47  vars:
48    algorithm: "{{ cresult.results[ansible_loop.index0].stdout.split() | first | lower }}"
49    checksum: "{{ cresult.results[ansible_loop.index0].stdout.split() | last }}"
50  when:
51    - bsd_cimage_debug | bool
52    - cresult.results[ansible_loop.index0].stdout is defined
53
54- name: "Download: Get images"
55  ansible.builtin.get_url:
56    url: "{{ [item.site, item.image] | community.general.path_join }}"
57    checksum: "{{ algorithm }}:{{ checksum }}"
58    dest: "{{ [bsd_cimage_dir, item.image] | community.general.path_join }}"
59    owner: "{{ bsd_cimage_owner | d(omit) }}"
60    group: "{{ bsd_cimage_group | d(omit) }}"
61    mode: "{{ bsd_cimage_mode | d(omit) }}"
62  register: gresult
63  loop: "{{ bsd_cimage_download }}"
64  loop_control:
65    label: "{{ item.image }}"
66    extended: true
67  vars:
68    algorithm: "{{ cresult.results[ansible_loop.index0].stdout.split() | first | lower }}"
69    checksum: "{{ cresult.results[ansible_loop.index0].stdout.split() | last }}"
70  when:
71    - bsd_cimage_get_images | d(true) | bool
72    - cresult.results[ansible_loop.index0].stdout is defined
73
74- name: "Download: Debug images"
75  ansible.builtin.debug:
76    var: gresult
77  when: bsd_cimage_debug | bool
78
79# EOF

mount.yml

Synopsis: Configure mount.

Description of the task.

[tasks/mount.yml]

 1---
 2- name: "Mount: Debug"
 3  vars:
 4    msg: |-
 5      bsd_cimage_mount_dir: {{ bsd_cimage_mount_dir }}
 6      bsd_cimage_mount_file: {{ bsd_cimage_mount_file }}
 7      bsd_cimage_mount_mode: {{ bsd_cimage_mount_mode }}
 8      bsd_cimage_mount_points_create: {{ bsd_cimage_mount_points_create }}
 9      bsd_cimage_mount_points:
10        {{ bsd_cimage_mount_points | to_yaml(indent=2) | indent(2) }}
11  ansible.builtin.debug:
12    msg: "{{ '{}'.format(msg) }}"
13  when: bsd_cimage_debug | bool
14
15- name: "Mount: Create mount points"
16  ansible.builtin.file:
17    state: directory
18    path: "{{ item.mountpoint }}"
19    mode: "{{ bsd_cimage_mount_mode }}"
20  loop: "{{ bsd_cimage_mount_points }}"
21  when: bsd_cimage_mount_points_create | bool # Note 2.
22  tags: bsd_cimage_mount_points
23
24- name: "Mount: Attach memory disk" # noqa: var-naming[no-role-prefix]
25  ansible.builtin.include_role:
26    name: vbotka.ansible_lib
27    tasks_from: al_mdconfig.yml
28  vars:
29    al_mdconfig_file: "{{ bsd_cimage_mount_dir }}/{{ bsd_cimage_mount_file }}"
30
31- name: "Mount: Set variable bsd_cimage_mount_dev"
32  ansible.builtin.set_fact:
33    bsd_cimage_mount_dev: md{{ al_mdconfig_devs[my_file]['unit'] | d('UNDEFINED') }}
34  vars:
35    my_file: "{{ bsd_cimage_mount_dir }}/{{ bsd_cimage_mount_file }}"
36  tags: bsd_cimage_mdconfig
37
38- name: "Mount: Debug {{ bsd_cimage_mount_dir ~ '/' ~ bsd_cimage_mount_file }}"
39  ansible.builtin.debug:
40    msg: "Mounted at: {{ bsd_cimage_mount_dev }}"
41  when: bsd_cimage_debug | bool
42  tags: bsd_cimage_mdconfig
43
44- name: "Mount: Mount partitions {{ bsd_cimage_mount_dev }}"
45  ansible.posix.mount:
46    src: /dev/{{ bsd_cimage_mount_dev }}{{ item.partition }}
47    path: "{{ item.mountpoint }}" # Note 2.
48    fstype: "{{ item.fstype }}"
49    state: mounted
50    fstab: /tmp/tmp.fstab # Note 1.
51  loop: "{{ bsd_cimage_mount_points }}"
52  register: result
53
54- name: "Mount: Debug mount results"
55  ansible.builtin.debug:
56    var: result
57  when: bsd_cimage_debug | bool
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.

[tasks/umount.yml]

 1---
 2- name: "Umount: Debug"
 3  vars:
 4    msg: |-
 5      bsd_cimage_mount_points:
 6      {{ bsd_cimage_mount_points | to_yaml(indent=2) | indent(2) }}
 7  ansible.builtin.debug:
 8    msg: "{{ '{}'.format(msg) }}"
 9  when: bsd_cimage_debug | bool
10
11- name: "Umount: Unmount"
12  ansible.posix.mount:
13    path: "{{ item.mountpoint }}"
14    state: unmounted
15    fstab: /tmp/tmp.fstab # Note 1.
16  loop: "{{ bsd_cimage_mount_points }}"
17  loop_control:
18    label: "{{ item.mountpoint }}"
19  register: result
20
21- name: "Umount: Debug unmount results"
22  ansible.builtin.debug:
23    var: result
24  when: bsd_cimage_debug | bool
25
26- name: "Umount: Detach memory disk" # noqa: var-naming[no-role-prefix]
27  ansible.builtin.include_role:
28    name: vbotka.ansible_lib
29    tasks_from: al_mdconfig.yml
30  vars:
31    al_mdconfig_file: "{{ bsd_cimage_mount_dir }}/{{ bsd_cimage_mount_file }}"
32    al_mdconfig_state: absent
33
34- name: "Umount: Debug detach memory disk"
35  ansible.builtin.debug:
36    var: al_mdconfig_devs
37  when: bsd_cimage_debug | bool
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.

[tasks/customize.yml]

 1---
 2- name: "Customize: Debug"
 3  vars:
 4    msg: |-
 5      bsd_cimage_mount_path: {{ bsd_cimage_mount_path }}
 6      bsd_cimage_loaderconf: {{ bsd_cimage_loaderconf }}
 7      bsd_cimage_rcconf: {{ bsd_cimage_rcconf }}
 8      bsd_cimage_wpasupconf: {{ bsd_cimage_wpasupconf }}
 9  ansible.builtin.debug:
10    msg: "{{ '{}'.format(msg) }}"
11  when: bsd_cimage_debug | bool
12
13- name: Include fn/loaderconf.yml
14  ansible.builtin.include_tasks: fn/loaderconf.yml
15  when: bsd_cimage_loaderconf | bool
16  tags: bsd_cimage_loaderconf
17
18- name: Include fn/rcconf.yml
19  ansible.builtin.include_tasks: fn/rcconf.yml
20  when: bsd_cimage_rcconf | bool
21  tags: bsd_cimage_rcconf
22
23- name: Include fn/wpasupconf.yml
24  ansible.builtin.include_tasks: fn/wpasupconf.yml
25  when: bsd_cimage_wpasupconf | bool
26  tags: bsd_cimage_wpasupconf
27
28# TODO: firstboot, wpa_cli
29
30# EOF

loaderconf.yml

Synopsis: Configure loaderconf.

Description of the task.

[tasks/fn/loaderconf.yml]

 1---
 2- name: "Loaderconf: Debug"
 3  vars:
 4    msg: |-
 5      bsd_cimage_loaderconf_backup: {{ bsd_cimage_loaderconf_backup }}
 6      bsd_cimage_loaderconf_modules:
 7        {{ bsd_cimage_loaderconf_modules | to_yaml(indent=2) | indent(2) }}
 8      bsd_cimage_loaderconf_data:
 9        {{ bsd_cimage_loaderconf_data | to_nice_yaml(indent=2) | indent(2) }}
10      bsd_cimage_loaderconf_sysctl:
11        {{ bsd_cimage_loaderconf_sysctl | to_nice_yaml(indent=2) | indent(2) }}
12  ansible.builtin.debug:
13    msg: "{{ '{}'.format(msg) }}"
14  when: bsd_cimage_debug | bool
15
16- name: "Loaderconf: Configure {{ bsd_cimage_mount_path ~ '/boot/loader.conf' }}"
17  ansible.builtin.template:
18    src: loader.conf.j2
19    dest: "{{ bsd_cimage_mount_path }}/boot/loader.conf"
20    owner: root
21    group: wheel
22    mode: "0644"
23    backup: "{{ bsd_cimage_loaderconf_backup }}"
24
25# EOF

rcconf.yml

Synopsis: Configure rcconf.

Description of the task.

[tasks/fn/rcconf.yml]

 1---
 2- name: "Rcconf: Debug"
 3  vars:
 4    msg: |-
 5      bsd_cimage_rcconf_backup: {{ bsd_cimage_rcconf_backup }}
 6      bsd_cimage_rcconf_data:
 7        {{ bsd_cimage_rcconf_data | to_yaml(indent=2) | indent(2) }}
 8  ansible.builtin.debug:
 9    msg: "{{ '{}'.format(msg) }}"
10  when: bsd_cimage_debug | bool
11
12- name: "Rcconf: Configure {{ bsd_cimage_mount_path ~ '/etc/rc.conf' }}"
13  ansible.builtin.lineinfile:
14    dest: "{{ bsd_cimage_mount_path }}/etc/rc.conf"
15    regexp: ^\s*{{ item.key }}\s*=(.*)$
16    line: "{{ item.key }}={{ item.value }}"
17    owner: root
18    group: wheel
19    mode: "0644"
20    backup: "{{ bsd_cimage_rcconf_backup }}"
21  loop: "{{ bsd_cimage_rcconf_data }}"
22
23# EOF

wpasupconf.yml

Synopsis: Configure wpasupconf.

Description of the task.

[tasks/fn/wpasupconf.yml]

 1---
 2- name: "Wpasupconf: Debug"
 3  vars:
 4    msg: |-
 5      bsd_cimage_wpasupconf_backup: {{ bsd_cimage_wpasupconf_backup }}
 6      bsd_cimage_wpasupconf_file: {{ bsd_cimage_wpasupconf_file }}
 7      bsd_cimage_wpasupconf_owner: {{ bsd_cimage_wpasupconf_owner }}
 8      bsd_cimage_wpasupconf_group: {{ bsd_cimage_wpasupconf_group }}
 9      bsd_cimage_wpasupconf_mode: {{ bsd_cimage_wpasupconf_mode }}
10      bsd_cimage_wpasupconf_global:
11        {{ bsd_cimage_wpasupconf_global | to_yaml(indent=2) | indent(2) }}
12      {% if bsd_cimage_debug_classified %}
13      bsd_cimage_wpasupconf_data:
14        {{ bsd_cimage_wpasupconf_data | to_yaml(indent=2) | indent(2) }}
15      {% endif %}
16      bsd_cimage_wpasupconf_link: {{ bsd_cimage_wpasupconf_link }}
17      bsd_cimage_wpasupconf_link_dev: {{ bsd_cimage_wpasupconf_link_dev }}
18  ansible.builtin.debug:
19    msg: "{{ '{}'.format(msg) }}"
20  when: bsd_cimage_debug | bool
21
22- name: "Wpasupconf: Configure {{ bsd_cimage_mount_path ~ '/etc/wpasupplicant.conf' }}"
23  ansible.builtin.template:
24    src: wpa_supplicant.conf.j2
25    dest: "{{ bsd_cimage_mount_path }}/{{ bsd_cimage_wpasupconf_file }}.{{ item.dev }}"
26    owner: "{{ bsd_cimage_wpasupconf_owner }}"
27    group: "{{ bsd_cimage_wpasupconf_group }}"
28    mode: "{{ bsd_cimage_wpasupconf_mode }}"
29    backup: "{{ bsd_cimage_wpasupconf_backup }}"
30  loop: "{{ bsd_cimage_wpasupconf_data }}"
31
32- name: "Wpasupconf: Link to {{ bsd_cimage_wpasupconf_file ~ '.' ~ bsd_cimage_wpasupconf_link_dev }}"
33  ansible.builtin.file:
34    state: link
35    src: wpa_supplicant.conf.{{ bsd_cimage_wpasupconf_link_dev }}
36    dest: "{{ bsd_cimage_mount_path }}/{{ bsd_cimage_wpasupconf_file }}"
37    force: true
38  when: bsd_cimage_wpasupconf_link | bool
39
40# EOF