Tasks

main.yml

Synopsis: Main task.

Import tasks if enabled.

[tasks/main.yml]

 1---
 2# tasks for ansible
 3
 4- name: Import vars.yml
 5  ansible.builtin.import_tasks: vars.yml
 6  tags: [ma_vars, always]
 7
 8- name: Import debug.yml
 9  ansible.builtin.import_tasks: debug.yml
10  when: ma_debug | bool
11  tags: ma_debug
12
13- name: Import sanity.yml
14  ansible.builtin.import_tasks: sanity.yml
15  when: ma_sanity | bool
16  tags: ma_sanity
17
18- name: Import pkg.yml
19  ansible.builtin.import_tasks: pkg.yml
20  when: ma_pkg_install | bool
21  tags: ma_pkg
22
23- name: Import pip.yml
24  ansible.builtin.import_tasks: pip.yml
25  when: ma_pip_install | bool
26  tags: ma_pip
27
28- name: Import venv.yml
29  ansible.builtin.import_tasks: venv.yml
30  when: ma_venv_install | bool
31  tags: ma_venv
32
33- name: Import ara.yml
34  ansible.builtin.import_tasks: ara.yml
35  when: ma_ara | bool
36  tags: ma_ara
37
38- name: Import plugins.yml
39  ansible.builtin.import_tasks: plugins.yml
40  when: ma_plugins | length > 0
41  tags: [ma_plugins, ma_config]
42
43- name: Import config.yml
44  ansible.builtin.import_tasks: config.yml
45  when: ma_config | length > 0
46  tags: ma_config
47
48- name: Import devel.yml
49  ansible.builtin.import_tasks: devel.yml
50  when: ma_devel | bool
51  tags: ma_devel
52
53# EOF
54...

ara.yml

Synopsis: Configure ara.

Description of the task.

[tasks/ara.yml]

 1---
 2
 3- name: "Ara: Debug"
 4  ansible.builtin.debug:
 5    msg: Not implemented yet.
 6
 7# [TODO]
 8#
 9# ARA Records Ansible playbooks
10# https://ara.recordsansible.org/
11#
12# Welcome to the ARA documentation!
13# https://ara.readthedocs.io/en/latest/index.html
14
15# EOF
16...

config.yml

Synopsis: Configure config.

Description of the task.

[tasks/config.yml]

 1---
 2
 3- name: "Config: Create directories for Ansible configuration"
 4  ansible.builtin.file:
 5    state: directory
 6    dest: "{{ item.path | dirname }}"
 7    mode: "{{ item.dmode | d('0755') }}"
 8  loop: "{{ ma_config }}"
 9  loop_control:
10    label: "{{ item.path | dirname }}"
11
12- name: "Config: Ansible configuration from template"
13  ansible.builtin.template:
14    src: "{{ item.template | d(ma_config_template_default) }}"
15    dest: "{{ item.path }}"
16    owner: "{{ item.owner }}"
17    group: "{{ item.group }}"
18    mode: "{{ item.mode }}"
19    backup: "{{ ma_backup_conf }}"
20  loop: "{{ ma_config }}"
21  loop_control:
22    label: "{{ item.path }}"
23  when: ma_config_type | lower == 'template'
24
25- name: "Config: Ansible configuration by lineinfile"
26  ansible.builtin.lineinfile:
27    path: "{{ item.0.path }}"
28    owner: "{{ item.0.owner }}"
29    group: "{{ item.0.group }}"
30    mode: "{{ item.0.mode }}"
31    regexp: ^{{ item.1.key }}
32    line: "{{ item.1.key }}={{ item.1.value }}"
33    insertafter: \[{{ item.1.section }}\]
34    create: true
35    backup: "{{ ma_backup_conf }}"
36  loop: "{{ ma_config | subelements('config') }}"
37  loop_control:
38    label: "{{ item.0.path }}"
39  when: ma_config_type | lower == 'lineinfile'
40
41- name: "Config: Ansible configuration by ini_file"
42  community.general.ini_file:
43    path: "{{ item.0.path }}"
44    owner: "{{ item.0.owner }}"
45    group: "{{ item.0.group }}"
46    mode: "{{ item.0.mode }}"
47    section: "{{ item.1.section }}"
48    option: "{{ item.1.key }}"
49    value: "{{ item.1.key }}={{ item.1.value }}"
50    create: true
51    backup: "{{ ma_backup_conf }}"
52  loop: "{{ ma_config | subelements('config') }}"
53  loop_control:
54    label: "{{ item.0.path }}"
55  when: ma_config_type | lower == 'ini_file'
56
57# EOF
58...

debug.yml

Synopsis: Configure debug.

Description of the task.

[tasks/debug.yml]

 1---
 2
 3- name: "Debug: Ansible ma_debug={{ ma_debug | bool }}"
 4  vars:
 5    msg: |-
 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      linux_install_retries: {{ linux_install_retries }}
19      linux_install_delay: {{ linux_install_delay }}
20      pip_install_retries: {{ pip_install_retries }}
21      pip_install_delay: {{ pip_install_delay }}
22
23      ma_supported_linux_family: {{ ma_supported_linux_family }}
24      ma_sanity: {{ ma_sanity }}
25      ma_sanity_pip_exclusive: {{ ma_sanity_pip_exclusive }}
26      ma_sanity_pip_owner_defined: {{ ma_sanity_pip_owner_defined }}
27      ma_sanity_pip_exists: {{ ma_sanity_pip_exists }}
28
29      ma_owner: {{ ma_owner }}
30      ma_backup_conf: {{ ma_backup_conf }}
31      ma_config_type: {{ ma_config_type }}
32      ma_config_template_default: {{ ma_config_template_default }}
33      ma_config:
34        {{ ma_config | to_yaml(indent=2) | indent(2) }}
35      ma_pip_install: {{ ma_pip_install }}
36      ma_pip_extraagrs: {{ ma_pip_extraagrs | d('UNDEFINED') }}
37      ma_pip_executable: {{ ma_pip_executable }}
38      ma_pip_executable_override: {{ ma_pip_executable_override | d('UNDEFINED') }}
39      ma_pip_requirements: {{ ma_pip_requirements }}
40      ma_pip_requirements_override: {{ ma_pip_requirements_override | d('UNDEFINED') }}
41      ma_pip_packages_state: {{ ma_pip_packages_state }}
42      ma_pip_packages:
43        {{ ma_pip_packages | to_yaml(indent=2) | indent(2) }}
44      ma_venv_install: {{ ma_venv_install }}
45      ma_virtualenv: {{ ma_virtualenv }}
46      ma_virtualenv_command: {{ ma_virtualenv_command | d('UNDEFINED') }}
47      ma_virtualenv_python: {{ ma_virtualenv_python | d('UNDEFINED') }}
48      ma_virtualenv_site_packages: {{ ma_virtualenv_site_packages | d('UNDEFINED') }}
49      ma_virtualenv_packages:
50        {{ ma_virtualenv_packages | to_yaml(indent=2) | indent(2) }}
51      ma_pkg_install: {{ ma_pkg_install }}
52      ma_packages_state: {{ ma_packages_state }}
53      ma_packages:
54        {{ ma_packages | to_yaml(indent=2) | indent(2) }}
55      ma_packages_override: {{ ma_packages_override | d('UNDEFINED') }}
56
57      ma_plugins_paths_list: {{ ma_plugins_paths_list }}
58      ma_plugins_path: {{ ma_plugins_path }}
59      ma_src_path: {{ ma_src_path }}
60      ma_plugins:
61        {{ ma_plugins | to_yaml(indent=2) | indent(2) }}
62      ma_ara: {{ ma_ara }}
63
64      ma_devel: {{ ma_devel }}
65      ma_devel_owner: {{ ma_devel_owner }}
66      ma_devel_group: {{ ma_devel_group | d('UNDEFINED') }}
67      ma_repo: {{ ma_repo }}
68      ma_repo_url: {{ ma_repo_url }}
69      ma_repo_version: {{ ma_repo_version }}
70      ma_repo_dir: {{ ma_repo_dir }}
71      ma_rnotes: {{ ma_rnotes }}
72      ma_rnotes_core_url: {{ ma_rnotes_core_url }}
73      ma_rnotes_core_dir: {{ ma_rnotes_core_dir }}
74      ma_rnotes_core_list: {{ ma_rnotes_core_list }}
75      ma_rnotes_build_url: {{ ma_rnotes_build_url }}
76      ma_rnotes_build_dir: {{ ma_rnotes_build_dir }}
77      ma_rnotes_build_list: {{ ma_rnotes_build_list }}
78
79  ansible.builtin.debug:
80    msg: "{{ '{}'.format(msg) }}"
81
82# EOF
83...

devel.yml

Synopsis: Configure devel.

Description of the task.

[tasks/devel.yml]

 1---
 2
 3- name: "Devel: Checkout repository"
 4  when: ma_repo | bool
 5  tags: ma_devel_repo
 6  block:
 7
 8    - name: "Devel: Create directory {{ ma_repo_dir }}"
 9      ansible.builtin.file:
10        state: directory
11        path: "{{ ma_repo_dir }}"
12        owner: "{{ ma_devel_owner }}"
13        group: "{{ ma_devel_group | d(omit) }}"
14        mode: "{{ ma_devel_dmode | d(omit) }}"
15      tags: ma_repo_path
16
17    - name: "Devel: Checkout {{ ma_repo_version }}"
18      become: "{{ ma_devel_owner }}"
19      ansible.builtin.git:
20        repo: "{{ ma_repo_url }}"
21        version: "{{ ma_repo_version }}"
22        dest: "{{ ma_repo_dir }}"
23
24- name: "Devel: Get release notes"
25  when: ma_rnotes | bool
26  tags: ma_devel_rnotes
27  block:
28
29    - name: "Devel: Create directories for release notes"
30      ansible.builtin.file:
31        state: directory
32        path: "{{ item }}"
33        owner: "{{ ma_devel_owner }}"
34        group: "{{ ma_devel_group | d(omit) }}"
35        mode: "{{ ma_devel_dmode | d(omit) }}"
36      loop:
37        - "{{ ma_rnotes_core_dir }}"
38        - "{{ ma_rnotes_build_dir }}"
39      tags: ma_rnotes_path
40
41    - name: "Devel: Get core release notes {{ ma_rnotes_core_list }}"
42      check_mode: false  # Note 1.
43      ansible.builtin.get_url:
44        url: "{{ _url }}"
45        dest: "{{ (ma_rnotes_core_dir, _file) | community.general.path_join }}"
46        owner: "{{ ma_devel_owner }}"
47        group: "{{ ma_devel_group }}"
48        mode: "0644"
49      loop: "{{ ma_rnotes_core_list }}"
50      loop_control:
51        label: "{{ _url }}"
52      vars:
53        _file: CHANGELOG-v{{ item }}.rst
54        _url: "{{ (ma_rnotes_core_url ~ item, 'changelogs', _file) |
55                  community.general.path_join }}"
56
57    - name: "Devel: Get build release notes {{ ma_rnotes_build_list }}"
58      check_mode: false #  Note 1.
59      ansible.builtin.get_url:
60        url: "{{ _url }}"
61        dest: "{{ (ma_rnotes_build_dir, _file) | community.general.path_join }}"
62        owner: "{{ ma_devel_owner }}"
63        group: "{{ ma_devel_group }}"
64        mode: "0644"
65      loop: "{{ ma_rnotes_build_list }}"
66      loop_control:
67        label: "{{ _url }}"
68      vars:
69        _file: CHANGELOG-v{{ item }}.rst
70        _url: "{{ (ma_rnotes_build_url, item, _file) | community.general.path_join }}"
71
72# Notes:
73#
74# 1) The module get_url does not support diff_mode. It will always
75#    report *changed* in check_mode.
76
77# EOF
78...

pkg.yml

Synopsis: Configure pkg.

Description of the task.

[tasks/pkg.yml]

1---
2
3- name: "Pkg: Include fn/packages.yml"
4  ansible.builtin.include_tasks: fn/packages.yml
5  vars:
6    ma_packages_incl: "{{ ma_packages }}"
7
8# EOF
9...

packages.yml

Synopsis: Configure packages.

Description of the task.

[tasks/fn/packages.yml]

 1---
 2
 3- name: FreeBSD packages
 4  when:
 5    - ansible_os_family == 'FreeBSD'
 6    - freebsd_install_method | lower == 'packages'
 7  block:
 8
 9    - name: "Packages: Install Ansible Lint FreeBSD packages"
10      community.general.pkgng:
11        name: "{{ item.name }}"
12        state: "{{ item.state | d(omit) }}"
13      loop: "{{ ma_packages_incl }}"
14      register: result
15      until: result is succeeded
16      retries: "{{ freebsd_install_retries }}"
17      delay: "{{ freebsd_install_delay }}"
18
19    - name: "Packages: Debug FreeBSD packages"
20      ansible.builtin.debug:
21        var: result
22      when: ma_debug | bool
23
24  rescue:
25
26    - name: "Packages: Rescue FreeBSD packages"
27      ansible.builtin.fail:
28        msg: |
29          [ERR] task {{ ansible_failed_task.name }} failed.
30          ansible_failed_task:
31            {{ ansible_failed_task | to_yaml(indent=2) | indent(2) }}
32          ansible_failed_result:
33            {{ ansible_failed_result | to_yaml(indent=2) | indent(2) }}
34
35- name: FreeBSD ports
36  when:
37    - ansible_os_family == 'FreeBSD'
38    - freebsd_install_method | lower == 'ports'
39  block:
40
41    - name: "Packages: Install Ansible Lint FreeBSD ports"
42      community.general.portinstall:
43        name: "{{ item.name }}"
44        use_packages: "{{ freebsd_use_packages }}"
45      loop: "{{ ma_packages_incl }}"
46      register: result
47      until: result is succeeded
48      retries: "{{ freebsd_install_retries }}"
49      delay: "{{ freebsd_install_delay }}"
50
51    - name: "Packages: Debug FreeBSD ports"
52      ansible.builtin.debug:
53        var: result
54      when: ma_debug | bool
55
56  rescue:
57
58    - name: "Packages: Rescue FreeBSD ports"
59      ansible.builtin.fail:
60        msg: |
61          [ERR] task {{ ansible_failed_task.name }} failed.
62          ansible_failed_task:
63            {{ ansible_failed_task | to_yaml(indent=2) | indent(2) }}
64          ansible_failed_result:
65            {{ ansible_failed_result | to_yaml(indent=2) | indent(2) }}
66
67- name: Linux packages
68  when: ansible_os_family in ma_supported_linux_family
69  block:
70
71    - name: "Packages: Install Ansible Lint Linux packages"
72      ansible.builtin.package:
73        name: "{{ item.name }}"
74        state: "{{ item.state | d(omit) }}"
75      loop: "{{ ma_packages_incl }}"
76      register: result
77      until: result is succeeded
78      retries: "{{ linux_install_retries }}"
79      delay: "{{ linux_install_delay }}"
80
81    - name: "Packages: Debug Linux packages"
82      ansible.builtin.debug:
83        var: result
84      when: ma_debug | bool
85
86  rescue:
87
88    - name: "Packages: Rescue Linux packages"
89      ansible.builtin.fail:
90        msg: |
91          [ERR] task {{ ansible_failed_task.name }} failed.
92          ansible_failed_task:
93            {{ ansible_failed_task | to_yaml(indent=2) | indent(2) }}
94          ansible_failed_result:
95            {{ ansible_failed_result | to_yaml(indent=2) | indent(2) }}
96
97# EOF
98...

pip.yml

Synopsis: Configure pip.

Description of the task.

[tasks/pip.yml]

 1---
 2
 3# TODO: Still open?
 4# The pip module always set to changed when using check mode #62826
 5# https://github.com/ansible/ansible/issues/62826
 6
 7# Note 1.
 8# The pip module isn't always idempotent #28952
 9# https://github.com/ansible/ansible/issues/28952
10# The isssue was closed. See the Conclusion
11
12- name: Install Ansible Lint PyPI packages for ma_owner
13  block:
14
15    - name: "Pip: Install Ansible Lint PyPI packages for {{ ma_owner }}"
16      become_user: "{{ ma_owner }}"
17      become: true
18      changed_when:
19        - result.changed
20        - not ansible_check_mode
21      ansible.builtin.pip:
22        name: "{{ item.name }}"
23        executable: "{{ ma_pip_executable }}"
24        extra_args: "{{ ma_pip_extraagrs | d(omit) }}"
25        version: "{{ item.version | d(omit) }}"
26        state: "{{ item.state | d(omit) }}"
27      loop: "{{ ma_pip_packages }}"
28      register: result
29      until: result is succeeded
30      retries: "{{ pip_install_retries }}"
31      delay: "{{ pip_install_delay }}"
32
33    - name: "Pip: Debug PyPI packages"
34      ansible.builtin.debug:
35        var: result
36      when: ma_debug | bool or ansible_check_mode
37
38  rescue:
39
40    - name: "Pip: Rescue PyPI packages"
41      ansible.builtin.fail:
42        msg: |
43          [ERR] task {{ ansible_failed_task.name }} failed.
44          ansible_failed_task:
45            {{ ansible_failed_task | to_yaml(indent=2) | indent(2) }}
46          ansible_failed_result:
47            {{ ansible_failed_result | to_yaml(indent=2) | indent(2) }}
48
49- name: Install Ansible Lint PyPI requirements for ma_owner
50  block:
51
52    - name: "Pip: Install Ansible Lint pip requirements for {{ ma_owner }}"
53      become_user: "{{ ma_owner }}"
54      become: true
55      changed_when:
56        - result.changed
57        - not ansible_check_mode
58      ansible.builtin.pip:
59        requirements: "{{ ma_pip_requirements }}"
60        executable: "{{ ma_pip_executable }}"
61        extra_args: "{{ pip_extraagrs | d(omit) }}"
62      register: result
63      until: result is succeeded
64      retries: "{{ pip_install_retries }}"
65      delay: "{{ pip_install_delay }}"
66      when: ma_pip_requirements | length > 0
67
68    - name: "Pip: Debug PyPI requirements"
69      ansible.builtin.debug:
70        var: result
71      when: ma_debug|bool
72
73  rescue:
74
75    - name: "Pip: Rescue PyPI requirements"
76      ansible.builtin.fail:
77        msg: |
78          [ERR] task {{ ansible_failed_task.name }} failed.
79          ansible_failed_task:
80            {{ ansible_failed_task | to_yaml(indent=2) | indent(2) }}
81          ansible_failed_result:
82            {{ ansible_failed_result | to_yaml(indent=2) | indent(2) }}
83
84# EOF
85...

plugins.yml

Synopsis: Configure plugins.

Description of the task.

[tasks/plugins.yml]

  1---
  2
  3- name: "Plugins: Create directory {{ ma_plugins_path }}"
  4  ansible.builtin.file:
  5    state: directory
  6    path: "{{ ma_plugins_path }}"
  7    mode: "{{ ma_plugins_path_mode | d(omit) }}"
  8  tags: ma_plugins_path
  9
 10- name: "Plugins: Create directory {{ ma_src_path }}"
 11  ansible.builtin.file:
 12    state: directory
 13    path: "{{ ma_src_path }}"
 14    mode: "{{ ma_src_path_mode | d(omit) }}"
 15  tags: ma_src_path
 16
 17- name: "Plugins: Download archives"
 18  ansible.builtin.get_url:
 19    url: "{{ item.archive_url }}"
 20    dest: "{{ ma_src_path }}/{{ item.archive }}"
 21    mode: "0644"
 22    checksum: "{{ item.checksum }}"
 23  loop: "{{ ma_plugins }}"
 24  loop_control:
 25    label: "{{ item.archive }}"
 26  tags: ma_plugins_download
 27
 28- name: "Plugins: Extract archives"
 29  ansible.builtin.unarchive:
 30    remote_src: true
 31    src: "{{ ma_src_path }}/{{ item.archive }}"
 32    dest: "{{ ma_plugins_path }}"
 33    creates: "{{ item.creates | d(omit) }}"
 34  loop: "{{ ma_plugins }}"
 35  loop_control:
 36    label: "{{ item.archive }}"
 37  tags: ma_plugins_extract
 38
 39- name: "Plugins: Create links"
 40  ansible.builtin.file:
 41    state: link
 42    src: "{{ ma_plugins_path }}/{{ item.dest }}"
 43    dest: "{{ ma_plugins_path }}/{{ item.link }}"
 44  loop: "{{ ma_plugins }}"
 45  loop_control:
 46    label: "{{ item.dest }}"
 47  when:
 48    - item.link is defined
 49    - item.dest is defined
 50  tags: ma_plugins_link
 51
 52- name: "Plugins: Create lists"
 53  tags: ma_plugins_lists
 54  block:
 55
 56    - name: "Plugins: Create list of used ini_keys ma_plugins_inikeys"
 57      ansible.builtin.set_fact:  # noqa: jinja[invalid]
 58        ma_plugins_inikeys: "{{ ma_plugins |
 59                                json_query('[].plugins[].ini_key') |
 60                                list | unique }}"
 61
 62    - name: "Plugins: Debug ma_plugins_inikeys"
 63      ansible.builtin.debug:
 64        var: ma_plugins_inikeys
 65      when: ma_debug | bool
 66
 67    - name: "Plugins: Create list of plugins ma_plugins_list"
 68      ansible.builtin.set_fact:  # noqa: jinja[invalid]
 69        ma_plugins_list: "{{ ma_plugins |
 70                             json_query('[].plugins[].{path: path,
 71                                                       ini_key: ini_key, enable: enable}') |
 72                             list }}"
 73
 74    - name: "Plugins: Debug ma_plugins_list"
 75      ansible.builtin.debug:
 76        var: ma_plugins_list
 77      when: ma_debug | bool
 78
 79    - name: "Plugins: Group plugins by ini_key to ma_plugins_grouped"
 80      ansible.builtin.set_fact:
 81        ma_plugins_grouped: "{{ ma_plugins_list | groupby('ini_key') }}"
 82
 83    - name: "Plugins: Debug ma_plugins_grouped"
 84      ansible.builtin.debug:
 85        var: ma_plugins_grouped
 86      when: ma_debug | bool
 87
 88    - name: "Plugins: Create list of ini_key ma_plugins_inikeys_list"
 89      ansible.builtin.set_fact:
 90        ma_plugins_inikeys_list: "{{ ma_plugins_sections.keys() }}"
 91
 92    - name: "Plugins: Debug ma_plugins_inikeys_list"
 93      ansible.builtin.debug:
 94        var: ma_plugins_inikeys_list
 95      when: ma_debug | bool
 96
 97    - name: "Plugins: Create lists of paths ma_plugins_paths_list"
 98      ansible.builtin.set_fact:
 99        ma_plugins_paths_list: "{{ ma_plugins_paths_list + [{item.0: _value}] }}"
100      loop: "{{ ma_plugins_grouped }}"
101      loop_control:
102        label: "{{ item.0 }}"
103      vars:
104        _value: "{{ {'paths': item.1 | json_query('[?enable].path')} }}"
105
106    - name: "Plugins: Debug ma_plugins_paths_list"
107      ansible.builtin.debug:
108        msg: "{{ item }}"
109      loop: "{{ ma_plugins_paths_list }}"
110      loop_control:
111        label: "{{ item.keys() | list | first }}"
112      when: ma_debug | bool
113
114- name: "Plugins: Test used ini_keys"
115  ansible.builtin.fail:
116    msg: "[ERR] wrong ini_key: {{ item }}"
117  loop: "{{ ma_plugins_inikeys }}"
118  when: item not in ma_plugins_inikeys_list
119  tags: ma_plugins_test_inikeys
120
121# EOF
122...

sanity.yml

Synopsis: Configure sanity.

Description of the task.

[tasks/sanity.yml]

 1---
 2
 3- name: "Sanity: Test ma_pip_install, ma_pkg_install, and ma_venv_install are mutually exclusive"
 4  ansible.builtin.assert:
 5    that: count|int < 2
 6    fail_msg: "[ERR] ma_pip_install, ma_pkg_install, and ma_venv_install are mutually exclusive."
 7  vars:
 8    count: "{{ [ma_pip_install, ma_pkg_install, ma_venv_install] |
 9               select |
10               length }}"
11  when: ma_sanity_pip_exclusive | bool
12
13- name: "Sanity: Test ma_owner is defined if ma_pip_install or ma_venv_install"
14  ansible.builtin.assert:
15    that: ma_owner is defined
16    fail_msg: "[ERR] Variable ma_owner required for pip and venv."
17  when:
18    - ma_sanity_pip_owner_defined | bool
19    - ma_pip_install|bool or ma_venv_install|bool
20
21- name: If ma_pip_install test existence of {{ ma_pip_executable }}
22  when:
23    - ma_sanity_pip_exists | bool
24    - ma_pip_install | bool
25  block:
26
27    - name: "Sanity: Stat {{ ma_pip_executable }}"
28      ansible.builtin.stat:
29        path: "{{ ma_pip_executable }}"
30      register: result
31
32    - name: "Sanity: If ma_pip_install test existence of {{ ma_pip_executable }}"
33      ansible.builtin.assert:
34        that: result.stat.exists
35        fail_msg: "[ERR] {{ ma_pip_executable }} required for pip."
36
37# [TODO]
38# when: ma_pip_install exist: python3-setuptools, python3-pip
39
40# EOF
41...

vars.yml

Synopsis: Configure vars.

Description of the task.

[tasks/vars.yml]

 1---
 2
 3- name: Declare ma_owner when undefined
 4  when: ma_owner is undefined
 5  block:
 6
 7    - name: "Vars: Get the user"
 8      ansible.builtin.setup:
 9        gather_subset: user
10      become: false
11
12    - name: "Vars: Debug user"
13      ansible.builtin.debug:
14        msg: |
15          ansible_user: {{ ansible_user | d('UDEFINED') }}
16          ansible_user_id: {{ ansible_user_id | d('UDEFINED') }}
17      when: ma_debug | bool
18
19    - name: "Vars: Declare ma_owner"
20      ansible.builtin.set_fact:
21        ma_owner: "{{ ansible_user | d(ansible_user_id) }}"
22
23- name: "Vars: Include OS vars"
24  ansible.builtin.include_role:  # noqa: var-naming[no-role-prefix]
25    name: vbotka.ansible_lib
26    tasks_from: al_include_os_vars_path
27  vars:
28    al_os_vars_path: "{{ ansible_parent_role_paths.0 }}"
29
30- name: "Vars: Override ma_packages"
31  ansible.builtin.set_fact:
32    ma_packages: "{{ ma_packages_override }}"
33  when: ma_packages_override is defined
34
35- name: "Vars: Override ma_pip_executable"
36  ansible.builtin.set_fact:
37    ma_pip_executable: "{{ ma_pip_executable_override }}"
38  when: ma_pip_executable_override is defined
39
40- name: "Vars: Override ma_pip_requirements"
41  ansible.builtin.set_fact:
42    ma_pip_requirements: "{{ ma_pip_requirements_override }}"
43  when: ma_pip_requirements_override is defined
44
45# EOF
46...

venv.yml

Synopsis: Configure venv.

Description of the task.

[tasks/venv.yml]

 1---
 2
 3- name: "Venv: Install packages for Python virtual environment."
 4  ansible.builtin.include_tasks: fn/packages.yml
 5  vars:
 6    ma_packages_incl: "{{ ma_virtualenv_packages }}"
 7  when: ma_virtualenv_packages|length > 0
 8
 9- name: Install Ansible Lint PyPI packages for ma_owner
10  block:
11
12    - name: "Venv: Install Ansible PyPI packages for {{ ma_owner }}"
13      become_user: "{{ ma_owner }}"
14      become: true
15      # changed_when: result.changed
16      ansible.builtin.pip:
17        name: "{{ item.name }}"
18        # executable: "{{ ma_pip_executable }}"
19        # extra_args: "{{ ma_pip_extraagrs | d(omit) }}"
20        version: "{{ item.version | d(omit) }}"
21        state: "{{ item.state | d(omit) }}"
22        virtualenv: "{{ ma_virtualenv }}"
23        virtualenv_command: "{{ ma_virtualenv_command | d(omit) }}"
24        virtualenv_python: "{{ ma_virtualenv_python | d(omit) }}"
25        virtualenv_site_packages: "{{ ma_virtualenv_site_packages | d(omit) }}"
26      loop: "{{ ma_pip_packages }}"
27      register: result
28      until: result is succeeded
29      retries: "{{ pip_install_retries }}"
30      delay: "{{ pip_install_delay }}"
31
32    - name: "Venv: Debug PyPI packages"
33      ansible.builtin.debug:
34        var: result
35      when: ma_debug | bool
36
37  rescue:
38
39    - name: "Venv: Rescue PyPI packages"
40      ansible.builtin.fail:
41        msg: |
42          [ERR] task {{ ansible_failed_task.name }} failed.
43          ansible_failed_task:
44            {{ ansible_failed_task | to_yaml(indent=2) | indent(2) }}
45          ansible_failed_result:
46            {{ ansible_failed_result | to_yaml(indent=2) | indent(2) }}
47
48# EOF
49...