Tasks

main.yml

Synopsis: Main task.

Import tasks if enabled.

[tasks/main.yml]

 1---
 2# tasks for ansible_runner
 3
 4- name: Import vars.yml
 5  ansible.builtin.import_tasks: vars.yml
 6  tags: [ar_vars, always]
 7
 8- name: Import debug.yml
 9  ansible.builtin.import_tasks: debug.yml
10  when: ar_debug | bool
11  tags: ar_debug
12
13- name: Import sanity.yml
14  ansible.builtin.import_tasks: sanity.yml
15  when: ar_sanity | bool
16  tags: ar_sanity
17
18- name: Import pkg.yml
19  ansible.builtin.import_tasks: pkg.yml
20  when: ar_pkg_install | bool
21  tags: ar_pkg
22
23- name: Import pip.yml
24  ansible.builtin.import_tasks: pip.yml
25  when: ar_pip_install | bool
26  tags: ar_pip
27
28- name: Import venv.yml
29  ansible.builtin.import_tasks: venv.yml
30  when: ar_venv_install | bool
31  tags: ar_venv
32
33- name: Import links.yml
34  ansible.builtin.import_tasks: links.yml
35  when: ar_links | length > 0
36  tags: ar_links
37
38- name: Import config.yml
39  ansible.builtin.import_tasks: config.yml
40  when: ar_config | length > 0
41  tags: ar_config
42
43# EOF
44...

vars.yml

Synopsis: Configure vars.

Description of the task.

[tasks/vars.yml]

 1---
 2
 3- name: Declare ar_owner when undefined
 4  when: ar_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: ar_debug | bool
18
19    - name: "Vars: Declare ar_owner"
20      ansible.builtin.set_fact:
21        ar_owner: "{{ ansible_user | d(ansible_user_id) }}"
22
23- name: "Vars: Include OS vars"  # noqa: var-naming[no-role-prefix]
24  ansible.builtin.include_role:
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 ar_packages"
31  ansible.builtin.set_fact:
32    ar_packages: "{{ ar_packages_override }}"
33  when: ar_packages_override is defined
34
35- name: "Vars: Override ar_pip_executable"
36  ansible.builtin.set_fact:
37    ar_pip_executable: "{{ ar_pip_executable_override }}"
38  when: ar_pip_executable_override is defined
39
40- name: "Vars: Override ar_pip_requirements"
41  ansible.builtin.set_fact:
42    ar_pip_requirements: "{{ ar_pip_requirements_override }}"
43  when: ar_pip_requirements_override is defined
44
45# EOF
46...

debug.yml

Synopsis: Configure debug.

Description of the task.

[tasks/debug.yml]

 1---
 2
 3- name: "Debug: Ansible Runner ar_debug={{ ar_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      ar_supported_linux_family: {{ ar_supported_linux_family }}
24      ar_sanity: {{ ar_sanity }}
25      ar_sanity_pip_exclusive: {{ ar_sanity_pip_exclusive }}
26      ar_sanity_pip_owner_defined: {{ ar_sanity_pip_owner_defined }}
27      ar_sanity_pip_exists: {{ ar_sanity_pip_exists }}
28
29      ar_owner: {{ ar_owner }}
30      ar_backup_conf: {{ ar_backup_conf }}
31      ar_config:
32        {{ ar_config | to_yaml(indent=2) | indent(2) }}
33      ar_pip_install: {{ ar_pip_install }}
34      ar_pip_extraagrs: {{ ar_pip_extraagrs | d('UNDEFINED') }}
35      ar_pip_executable: {{ ar_pip_executable }}
36      ar_pip_executable_override: {{ ar_pip_executable_override | d('UNDEFINED') }}
37      ar_pip_requirements: {{ ar_pip_requirements }}
38      ar_pip_requirements_override: {{ ar_pip_requirements_override | d('UNDEFINED') }}
39      ar_pip_packages_state: {{ ar_pip_packages_state }}
40      ar_pip_packages:
41        {{ ar_pip_packages | to_yaml(indent=2) | indent(2) }}
42      ar_venv_install: {{ ar_venv_install }}
43      ar_virtualenv: {{ ar_virtualenv }}
44      ar_virtualenv_command: {{ ar_virtualenv_command | d('UNDEFINED') }}
45      ar_virtualenv_python: {{ ar_virtualenv_python | d('UNDEFINED') }}
46      ar_virtualenv_site_packages: {{ ar_virtualenv_site_packages | d('UNDEFINED') }}
47      ar_virtualenv_packages:
48        {{ ar_virtualenv_packages | to_yaml(indent=2) | indent(2) }}
49      ar_pkg_install: {{ ar_pkg_install }}
50      ar_packages_state: {{ ar_packages_state }}
51      ar_packages:
52        {{ ar_packages | to_yaml(indent=2) | indent(2) }}
53      ar_packages_override: {{ ar_packages_override | d('UNDEFINED') }}
54      ar_links:
55        {{ ar_links | to_nice_yaml(indent=2) | indent(2) }}
56
57  ansible.builtin.debug:
58    msg: "{{ '{}'.format(msg) }}"
59
60# EOF
61...

sanity.yml

Synopsis: Configure sanity.

Description of the task.

[tasks/sanity.yml]

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

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    ar_packages_incl: "{{ ar_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: "{{ ar_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: ar_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: "{{ ar_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: ar_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 ar_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: "{{ ar_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: ar_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# 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 Runner PyPI packages for ar_owner
12  block:
13
14    - name: "Pip: Install Ansible Runner PyPI packages for {{ ar_owner }}"
15      become_user: "{{ ar_owner }}"
16      become: true
17      changed_when:
18        - result.changed
19        - not ansible_check_mode
20      ansible.builtin.pip:
21        name: "{{ item.name }}"
22        executable: "{{ ar_pip_executable }}"
23        extra_args: "{{ ar_pip_extraagrs | d(omit) }}"
24        version: "{{ item.version | d(omit) }}"
25        state: "{{ item.state | d(omit) }}"
26      loop: "{{ ar_pip_packages }}"
27      register: result
28      until: result is succeeded
29      retries: "{{ pip_install_retries }}"
30      delay: "{{ pip_install_delay }}"
31
32    - name: "Pip: Debug PyPI packages"
33      ansible.builtin.debug:
34        var: result
35      when: ar_debug | bool or ansible_check_mode
36
37  rescue:
38
39    - name: "Pip: 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- name: Install Ansible Runner PyPI requirements for ar_owner
49  block:
50    - name: "Pip: Install Ansible Runner pip requirements for {{ ar_owner }}"
51      become_user: "{{ ar_owner }}"
52      become: true
53      changed_when:
54        - result.changed
55        - not ansible_check_mode
56      ansible.builtin.pip:
57        requirements: "{{ ar_pip_requirements }}"
58        executable: "{{ ar_pip_executable }}"
59        extra_args: "{{ pip_extraagrs | d(omit) }}"
60      register: result
61      until: result is succeeded
62      retries: "{{ pip_install_retries }}"
63      delay: "{{ pip_install_delay }}"
64      when: ar_pip_requirements | length > 0
65
66    - name: "Pip: Debug PyPI requirements"
67      ansible.builtin.debug:
68        var: result
69      when: ar_debug | bool
70
71  rescue:
72    - name: "Pip: Rescue PyPI requirements"
73      ansible.builtin.fail:
74        msg: |
75          [ERR] task {{ ansible_failed_task.name }} failed.
76          ansible_failed_task:
77            {{ ansible_failed_task | to_yaml(indent=2) | indent(2) }}
78          ansible_failed_result:
79            {{ ansible_failed_result | to_yaml(indent=2) | indent(2) }}
80
81# EOF
82...

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    ar_packages_incl: "{{ ar_virtualenv_packages }}"
 7  when: ar_virtualenv_packages|length > 0
 8
 9- name: Install Ansible Lint PyPI packages for ar_owner
10  block:
11
12    - name: "Venv: Install Ansible PyPI packages for {{ ar_owner }}"
13      become_user: "{{ ar_owner }}"
14      become: true
15      # changed_when: result.changed
16      ansible.builtin.pip:
17        name: "{{ item.name }}"
18        # executable: "{{ ar_pip_executable }}"
19        # extra_args: "{{ ar_pip_extraagrs | d(omit) }}"
20        version: "{{ item.version | d(omit) }}"
21        state: "{{ item.state | d(omit) }}"
22        virtualenv: "{{ ar_virtualenv }}"
23        virtualenv_command: "{{ ar_virtualenv_command | d(omit) }}"
24        virtualenv_python: "{{ ar_virtualenv_python | d(omit) }}"
25        virtualenv_site_packages: "{{ ar_virtualenv_site_packages | d(omit) }}"
26      loop: "{{ ar_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: ar_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...

config.yml

Synopsis: Configure config.

Description of the task.

[tasks/config.yml]

1---
2
3- name: "Config: Configure ansible-runner"
4  ansible.builtin.debug:
5    msg: No config
6  when: ar_debug | bool
7
8# EOF
9...