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

ara.yml

Synopsis: Configure ara.

Description of the task.

[tasks/ara.yml]

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

config.yml

Synopsis: Configure config.

Description of the task.

[tasks/config.yml]

 1---
 2- name: "Config: Create directories for Ansible configuration"
 3  ansible.builtin.file:
 4    state: directory
 5    dest: "{{ item.path | dirname }}"
 6    mode: "{{ item.dmode | d('0755') }}"
 7  loop: "{{ ma_config }}"
 8  loop_control:
 9    label: "{{ item.path | dirname }}"
10
11- name: "Config: Ansible configuration from template"
12  when: ma_config_type | lower == '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
24- name: "Config: Ansible configuration by lineinfile"
25  when: ma_config_type | lower == '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
40- name: "Config: Ansible configuration by ini_file"
41  when: ma_config_type | lower == '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
56# EOF

debug.yml

Synopsis: Configure debug.

Description of the task.

[tasks/debug.yml]

 1---
 2- name: "Debug: Ansible ma_debug={{ ma_debug | bool }}"
 3  vars:
 4    msg: |-
 5      ma_role_version: {{ ma_role_version }}
 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

devel.yml

Synopsis: Configure devel.

Description of the task.

[tasks/devel.yml]

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

pkg.yml

Synopsis: Configure pkg.

Description of the task.

[tasks/pkg.yml]

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

packages.yml

Synopsis: Configure packages.

Description of the task.

[tasks/fn/packages.yml]

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

pip.yml

Synopsis: Configure pip.

Description of the task.

[tasks/pip.yml]

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

plugins.yml

Synopsis: Configure plugins.

Description of the task.

[tasks/plugins.yml]

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

sanity.yml

Synopsis: Configure sanity.

Description of the task.

[tasks/sanity.yml]

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

vars.yml

Synopsis: Configure vars.

Description of the task.

[tasks/vars.yml]

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

venv.yml

Synopsis: Configure venv.

Description of the task.

[tasks/venv.yml]

 1---
 2- name: "Venv: Install packages for Python virtual environment."
 3  when: ma_virtualenv_packages | length > 0
 4  vars:
 5    ma_packages_incl: "{{ ma_virtualenv_packages }}"
 6  ansible.builtin.include_tasks: fn/packages.yml
 7
 8- name: Install Ansible Lint PyPI packages for ma_owner
 9  block:
10
11    - name: "Venv: Install Ansible PyPI packages for {{ ma_owner }}"
12      become_user: "{{ ma_owner }}"
13      become: true
14      register: result
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      until: result is succeeded
28      retries: "{{ pip_install_retries }}"
29      delay: "{{ pip_install_delay }}"
30
31    - name: "Venv: Debug PyPI packages ma_debug={{ ma_debug }}"
32      when: ma_debug | bool
33      ansible.builtin.debug:
34        var: result
35
36  rescue:
37
38    - name: "Venv: Rescue PyPI packages"
39      ansible.builtin.fail:
40        msg: |
41          [ERR] task {{ ansible_failed_task.name }} failed.
42          ansible_failed_task:
43            {{ ansible_failed_task | to_yaml(indent=2) | indent(2) }}
44          ansible_failed_result:
45            {{ ansible_failed_result | to_yaml(indent=2) | indent(2) }}
46
47# EOF