fix(vpn-node-config): resolve ansible-lint violations
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Canceled after 0s
OpenVPN Ansible / Generate SBOM (push) Canceled after 0s
OpenVPN Ansible / Scan SBOM with Trivy (push) Canceled after 0s
OpenVPN Ansible / Ansible Syntax Check (push) Canceled after 38s
OpenVPN Ansible / Ansible Lint (push) Canceled after 40s

This commit is contained in:
2026-11-11 12:13:20 +01:00
parent acb5c4ba82
commit 72fb458dab
3659 changed files with 471307 additions and 12 deletions
@@ -0,0 +1,9 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
collections:
- ansible.posix
- community.crypto
- community.docker
@@ -0,0 +1,6 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# No AIX LPAR available
unsupported
@@ -0,0 +1,81 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Scan new devices.
community.general.aix_devices:
device: all
state: present
- name: Scan new virtual devices (vio0).
community.general.aix_devices:
device: vio0
state: present
- name: Removing IP alias to en0
community.general.aix_devices:
device: en0
attributes:
delalias4: 10.0.0.100,255.255.255.0
- name: Removes ent2.
community.general.aix_devices:
device: ent2
state: absent
- name: Put device en2 in Defined
community.general.aix_devices:
device: en2
state: defined
- name: Removes ent4 (inexistent).
community.general.aix_devices:
device: ent4
state: absent
- name: Put device en4 in Defined (inexistent)
community.general.aix_devices:
device: en4
state: defined
- name: Put vscsi1 and children devices in Defined state.
community.general.aix_devices:
device: vscsi1
recursive: true
state: defined
- name: Removes vscsi1 and children devices.
community.general.aix_devices:
device: vscsi1
recursive: true
state: absent
- name: Changes en1 mtu to 9000 and disables arp.
community.general.aix_devices:
device: en1
attributes:
mtu: 900
arp: 'off'
state: present
- name: Configure IP, netmask and set en1 up.
community.general.aix_devices:
device: en1
attributes:
netaddr: 192.168.0.100
netmask: 255.255.255.0
state: up
state: present
- name: Adding IP alias to en0
community.general.aix_devices:
device: en0
attributes:
alias4: 10.0.0.100,255.255.255.0
state: present
@@ -0,0 +1,5 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
unsupported
@@ -0,0 +1,130 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Umounting /testfs
community.general.aix_filesystem:
filesystem: /testfs
state: unmounted
- name: Removing /testfs
community.general.aix_filesystem:
filesystem: /testfs
state: absent
- name: Creating a new file system
community.general.aix_filesystem:
filesystem: /newfs
size: 1G
state: present
vg: datavg
# It requires a host (nfshost) exporting the NFS
- name: Creating NFS filesystem from nfshost (Linux NFS server)
community.general.aix_filesystem:
device: /home/ftp
nfs_server: nfshost
filesystem: /nfs/ftp
state: present
# It requires a volume group named datavg (next three actions)
- name: Creating a logical volume testlv (aix_lvol module)
community.general.aix_lvol:
vg: datavg
lv: testlv
size: 2G
state: present
- name: Create filesystem in a previously defined logical volume
community.general.aix_filesystem:
device: testlv
filesystem: /testfs
state: present
- name: Create an already existing filesystem using existing logical volume.
community.general.aix_filesystem:
vg: datavg
device: mksysblv
filesystem: /mksysb
state: present
- name: Create a filesystem in a non-existing VG
community.general.aix_filesystem:
vg: nonexistvg
filesystem: /newlv
state: present
- name: Resizing /mksysb to 1G
community.general.aix_filesystem:
filesystem: /mksysb
size: 1G
state: present
- name: Resizing /mksysb to +512M
community.general.aix_filesystem:
filesystem: /mksysb
size: +512M
state: present
- name: Resizing /mksysb to 11G
community.general.aix_filesystem:
filesystem: /mksysb
size: 11G
state: present
- name: Resizing /mksysb to 11G (already done)
community.general.aix_filesystem:
filesystem: /mksysb
size: 11G
state: present
- name: Resizing /mksysb to -2G
community.general.aix_filesystem:
filesystem: /mksysb
size: -2G
state: present
- name: Resizing /mksysb to 100G (not enough space)
community.general.aix_filesystem:
filesystem: /mksysb
size: +100G
state: present
- name: Unmount filesystem /home/ftp
community.general.aix_filesystem:
filesystem: /home/ftp
state: unmounted
- name: Remove NFS filesystem /home/ftp
community.general.aix_filesystem:
filesystem: /home/ftp
rm_mount_point: true
state: absent
- name: Mount filesystem /newfs
community.general.aix_filesystem:
filesystem: /newfs
state: mounted
- name: Remove mounted /newfs
community.general.aix_filesystem:
filesystem: /newfs
rm_mount_point: true
state: absent
- name: Umount /newfs
community.general.aix_filesystem:
filesystem: /newfs
state: unmounted
- name: Remove /newfs
community.general.aix_filesystem:
filesystem: /newfs
rm_mount_point: true
state: absent
@@ -0,0 +1,6 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/1
disabled
@@ -0,0 +1,9 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
alerta_url: http://localhost:8080/
alerta_user: admin@example.com
alerta_password: password
alerta_key: demo-key
@@ -0,0 +1,156 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create customer (check mode)
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_username: "{{ alerta_user }}"
api_password: "{{ alerta_password }}"
customer: customer1
match: admin@admin.admin
check_mode: true
register: result
- name: Check result (check mode)
ansible.builtin.assert:
that:
- result is changed
- name: Create customer
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_username: "{{ alerta_user }}"
api_password: "{{ alerta_password }}"
customer: customer1
match: admin@admin.admin
register: result
- name: Check customer creation
ansible.builtin.assert:
that:
- result is changed
- name: Test customer creation idempotency
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_username: "{{ alerta_user }}"
api_password: "{{ alerta_password }}"
customer: customer1
match: admin@admin.admin
register: result
- name: Check customer creation idempotency
ansible.builtin.assert:
that:
- result is not changed
- name: Delete customer (check mode)
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_username: "{{ alerta_user }}"
api_password: "{{ alerta_password }}"
customer: customer1
match: admin@admin.admin
state: absent
check_mode: true
register: result
- name: Check customer deletion (check mode)
ansible.builtin.assert:
that:
- result is changed
- name: Delete customer
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_username: "{{ alerta_user }}"
api_password: "{{ alerta_password }}"
customer: customer1
match: admin@admin.admin
state: absent
register: result
- name: Check customer deletion
ansible.builtin.assert:
that:
- result is changed
- name: Test customer deletion idempotency
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_username: "{{ alerta_user }}"
api_password: "{{ alerta_password }}"
customer: customer1
match: admin@admin.admin
state: absent
register: result
- name: Check customer deletion idempotency
ansible.builtin.assert:
that:
- result is not changed
- name: Delete non-existing customer (check mode)
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_username: "{{ alerta_user }}"
api_password: "{{ alerta_password }}"
customer: customer1
match: admin@admin.admin
state: absent
check_mode: true
register: result
- name: Check non-existing customer deletion (check mode)
ansible.builtin.assert:
that:
- result is not changed
- name: Create customer with api key
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_key: "{{ alerta_key }}"
customer: customer1
match: admin@admin.admin
register: result
- name: Check customer creation with api key
ansible.builtin.assert:
that:
- result is changed
- name: Delete customer with api key
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_key: "{{ alerta_key }}"
customer: customer1
match: admin@admin.admin
state: absent
register: result
- name: Check customer deletion with api key
ansible.builtin.assert:
that:
- result is changed
- name: Use wrong api key
community.general.alerta_customer:
alerta_url: "{{ alerta_url }}"
api_key: wrong_key
customer: customer1
match: admin@admin.admin
register: result
ignore_errors: true
- name: Check customer creation with api key
ansible.builtin.assert:
that:
- result is not changed
- result is failed
@@ -0,0 +1,9 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
destructive
needs/root
skip/freebsd
skip/macos
@@ -0,0 +1,99 @@
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) 2017 Pierre-Louis Bonicoli <pierre-louis.bonicoli@libregerbil.fr>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: 'setup: create a dummy alternative'
block:
- ansible.builtin.import_tasks: setup.yml
##############
# Test parameters:
# link parameter present / absent ('with_link' variable)
# with / without alternatives defined in alternatives file ('with_alternatives' variable)
# auto / manual ('mode' variable)
- ansible.builtin.include_tasks: tests.yml
with_nested:
- [true, false] # with_link
- [true, false] # with_alternatives
- ['auto', 'manual'] # mode
loop_control:
loop_var: test_conf
##########
# Priority
- block:
- ansible.builtin.include_tasks: remove_links.yml
- ansible.builtin.include_tasks: setup_test.yml
# at least two iterations again
- ansible.builtin.include_tasks: tests_set_priority.yml
with_sequence: start=3 end=4
vars:
with_alternatives: true
mode: auto
- block:
- ansible.builtin.include_tasks: remove_links.yml
- ansible.builtin.include_tasks: setup_test.yml
# at least two iterations again
- ansible.builtin.include_tasks: tests_set_priority.yml
with_sequence: start=3 end=4
vars:
with_alternatives: false
mode: auto
# Test that path is checked: alternatives must fail when path is nonexistent
- ansible.builtin.import_tasks: path_is_checked.yml
# Test that subcommands commands work
- ansible.builtin.import_tasks: subcommands.yml
# Test operation of the 'state' parameter
- block:
- ansible.builtin.include_tasks: remove_links.yml
- ansible.builtin.include_tasks: tests_state.yml
# Test for the family parameter
- block:
- ansible.builtin.include_tasks: remove_links.yml
- ansible.builtin.include_tasks: tests_family.yml
when: ansible_facts.os_family == 'RedHat'
# Cleanup
always:
- ansible.builtin.include_tasks: remove_links.yml
- ansible.builtin.file:
path: '{{ item }}'
state: absent
with_items:
- '{{ alternatives_dir }}/dummy'
- '{{ alternatives_dir }}/dummymain'
- '{{ alternatives_dir }}/dummysubcmd'
- ansible.builtin.file:
path: '/usr/bin/dummy{{ item }}'
state: absent
with_sequence: start=1 end=4
# *Disable tests on Fedora 24*
# Shippable Fedora 24 image provides chkconfig-1.7-2.fc24.x86_64 but not the
# latest available version (chkconfig-1.8-1.fc24.x86_64). update-alternatives
# in chkconfig-1.7-2 fails when /etc/alternatives/dummy link is missing,
# error is: 'failed to read link /usr/bin/dummy: No such file or directory'.
# Moreover Fedora 24 is no longer maintained.
#
# *Disable tests on Arch Linux*
# TODO: figure out whether there is an alternatives tool for Arch Linux
#
# *Disable tests on Alpine*
# TODO: figure out whether there is an alternatives tool for Alpine
when:
- ansible_facts.distribution != 'Fedora' or ansible_facts.distribution_major_version|int > 24
- ansible_facts.distribution != 'Archlinux'
- ansible_facts.distribution != 'Alpine'
@@ -0,0 +1,17 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Try with nonexistent path
community.general.alternatives:
name: dummy
path: '/non/existent/path/there'
link: '/usr/bin/dummy'
ignore_errors: true
register: alternative
- name: Check previous task failed
ansible.builtin.assert:
that:
- 'alternative is failed'
@@ -0,0 +1,13 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: remove links
ansible.builtin.file:
path: '{{ item }}'
state: absent
with_items:
- "{{ alternatives_dir }}/dummy"
- /etc/alternatives/dummy
- /usr/bin/dummy
@@ -0,0 +1,19 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- ansible.builtin.include_vars: '{{ item }}'
with_first_found:
- files:
- '{{ ansible_facts.os_family }}-{{ ansible_facts.distribution_version }}.yml'
- '{{ ansible_facts.os_family }}.yml'
- default.yml
paths: ../vars
- ansible.builtin.template:
src: dummy_command
dest: /usr/bin/dummy{{ item }}
owner: root
group: root
mode: '0755'
with_sequence: start=1 end=4
@@ -0,0 +1,16 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- ansible.builtin.template:
src: dummy_alternative
dest: '{{ alternatives_dir }}/dummy'
owner: root
group: root
mode: '0644'
when: with_alternatives or ansible_facts.os_family != 'RedHat'
- ansible.builtin.file:
path: '{{ alternatives_dir }}/dummy'
state: absent
when: not with_alternatives and ansible_facts.os_family == 'RedHat'
@@ -0,0 +1,222 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Try with subcommands
community.general.alternatives:
name: dummymain
path: '/usr/bin/dummy1'
link: '/usr/bin/dummymain'
subcommands:
- name: dummysubcmd
path: '/usr/bin/dummy2'
link: '/usr/bin/dummysubcmd'
register: alternative
- name: Check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is changed'
- name: Execute the current dummymain command
ansible.builtin.command: dummymain
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy1"
- name: Execute the current dummysubcmd command
ansible.builtin.command: dummysubcmd
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy2"
- name: Get dummymain alternatives output
ansible.builtin.command:
cmd: '{{ alternatives_command }} --display dummymain'
register: result
- name: Print result
ansible.builtin.debug:
var: result.stdout_lines
- name: Subcommands are not removed if not specified
community.general.alternatives:
name: dummymain
path: '/usr/bin/dummy1'
link: '/usr/bin/dummymain'
register: alternative
- name: Check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is not changed'
- name: Execute the current dummysubcmd command
ansible.builtin.command: dummysubcmd
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy2"
- name: Subcommands are removed if set to an empty list
community.general.alternatives:
name: dummymain
path: '/usr/bin/dummy1'
link: '/usr/bin/dummymain'
subcommands: []
register: alternative
- name: Check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is changed'
- name: Execute the current dummysubcmd command
ansible.builtin.command: dummysubcmd
register: cmd
ignore_errors: true
- name: Ensure that the subcommand is gone
ansible.builtin.assert:
that:
- cmd.rc == 2
- '"No such file" in cmd.msg or "Error executing command." == cmd.msg'
- name: Get dummymain alternatives output
ansible.builtin.command:
cmd: '{{ alternatives_command }} --display dummymain'
register: result
- name: Print result
ansible.builtin.debug:
var: result.stdout_lines
- name: Install other alternative with subcommands
community.general.alternatives:
name: dummymain
path: '/usr/bin/dummy3'
link: '/usr/bin/dummymain'
subcommands:
- name: dummysubcmd
path: '/usr/bin/dummy4'
link: '/usr/bin/dummysubcmd'
register: alternative
- name: Check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is changed'
- name: Execute the current dummymain command
ansible.builtin.command: dummymain
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy3"
- name: Execute the current dummysubcmd command
ansible.builtin.command: dummysubcmd
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy4"
- name: Get dummymain alternatives output
ansible.builtin.command:
cmd: '{{ alternatives_command }} --display dummymain'
register: result
- name: Print result
ansible.builtin.debug:
var: result.stdout_lines
- name: Switch to first alternative
community.general.alternatives:
name: dummymain
path: '/usr/bin/dummy1'
register: alternative
- name: Check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is changed'
- name: Execute the current dummymain command
ansible.builtin.command: dummymain
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy1"
- name: Execute the current dummysubcmd command
ansible.builtin.command: dummysubcmd
register: cmd
ignore_errors: true
- name: Ensure that the subcommand is gone
ansible.builtin.assert:
that:
- cmd.rc == 2
- '"No such file" in cmd.msg or "Error executing command." == cmd.msg'
- name: Get dummymain alternatives output
ansible.builtin.command:
cmd: '{{ alternatives_command }} --display dummymain'
register: result
- name: Print result
ansible.builtin.debug:
var: result.stdout_lines
- name: Switch to second alternative
community.general.alternatives:
name: dummymain
path: '/usr/bin/dummy3'
register: alternative
- name: Check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is changed'
- name: Execute the current dummymain command
ansible.builtin.command: dummymain
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy3"
- name: Execute the current dummysubcmd command
ansible.builtin.command: dummysubcmd
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy4"
- name: Get dummymain alternatives output
ansible.builtin.command:
cmd: '{{ alternatives_command }} --display dummymain'
register: result
- name: Print result
ansible.builtin.debug:
var: result.stdout_lines
@@ -0,0 +1,56 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- ansible.builtin.debug:
msg: ' with_alternatives: {{ with_alternatives }}, mode: {{ mode }}'
- block:
- name: set alternative (using link parameter)
community.general.alternatives:
name: dummy
path: '/usr/bin/dummy{{ item }}'
link: '/usr/bin/dummy'
register: alternative
- name: check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is successful'
- 'alternative is changed'
when: with_link
- block:
- name: set alternative (without link parameter)
community.general.alternatives:
name: dummy
path: '/usr/bin/dummy{{ item }}'
register: alternative
- name: check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is successful'
- 'alternative is changed'
when: not with_link
- name: execute dummy command
ansible.builtin.command: dummy
register: cmd
- name: check expected command was executed
ansible.builtin.assert:
that:
- 'cmd.stdout == "dummy" ~ item'
- name: 'check mode (manual: alternatives file existed, it has been updated)'
ansible.builtin.shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^manual$"'
when: ansible_facts.os_family != 'RedHat' or with_alternatives or item != 1
- name: 'check mode (auto: alternatives file didn''t exist, it has been created)'
ansible.builtin.shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^auto$"'
when: ansible_facts.os_family == 'RedHat' and not with_alternatives and item == 1
- name: check that alternative has been updated
ansible.builtin.command: "grep -Pzq '/bin/dummy{{ item }}\\n' '{{ alternatives_dir }}/dummy'"
@@ -0,0 +1,20 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- ansible.builtin.include_tasks: remove_links.yml
- ansible.builtin.include_tasks: setup_test.yml
# at least two iterations:
# - first will use 'link currently absent',
# - second will receive 'link currently points to'
- ansible.builtin.include_tasks: test.yml
with_sequence: start=1 end=2
vars:
with_link: '{{ test_conf[0] }}'
with_alternatives: '{{ test_conf[1] }}'
mode: '{{ test_conf[2] }}'
# update-alternatives included in Fedora 26 (1.10) & Red Hat 7.4 (1.8) doesn't provide
# '--query' switch, 'link' is mandatory for these distributions.
when: ansible_facts.os_family != 'RedHat' or test_conf[0]
@@ -0,0 +1,65 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Add an alternative with a family
community.general.alternatives:
name: dummy
path: /usr/bin/dummy1
link: /usr/bin/dummy
family: family1
priority: 100
state: selected
- name: Ensure that the alternative has family assigned
ansible.builtin.command: 'grep family1 {{ alternatives_dir }}/dummy'
- name: Add two alternatives with different families
community.general.alternatives:
name: dummy
path: '/usr/bin/dummy{{ item.n }}'
link: /usr/bin/dummy
family: family2
priority: "{{ item.priority }}"
state: present
loop:
- { n: 2, priority: 20 }
- { n: 3, priority: 10 }
- { n: 4, priority: 5 }
# Here we select the whole family of alternatives
- name: Set family as an alternatives
community.general.alternatives:
name: dummy
family: family2
state: selected
- name: Ensure manual mode
ansible.builtin.shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^manual"'
- name: Execute the current dummy command
ansible.builtin.command: dummy
register: cmd
# Despite the fact that there is alternative with higher priority (/usr/bin/dummy1),
# it is not chosen as it doesn't belong to the selected family
- name: Ensure that the alternative from the selected family is used
ansible.builtin.assert:
that:
- cmd.stdout == "dummy2"
- name: Remove the alternative with the highest priority that belongs to the family
community.general.alternatives:
name: dummy
path: '/usr/bin/dummy2'
state: absent
- name: Execute the current dummy command
ansible.builtin.command: dummy
register: cmd
- name: Ensure that the next alternative is selected as having the highest priority from the family
ansible.builtin.assert:
that:
- cmd.stdout == "dummy3"
@@ -0,0 +1,54 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: update dummy alternative
community.general.alternatives:
name: dummy
path: '/usr/bin/dummy{{ item }}'
link: /usr/bin/dummy
priority: '{{ 60 + item|int }}'
register: alternative
- name: execute dummy command
ansible.builtin.command: dummy
register: cmd
- name: check if link group is in manual mode
ansible.builtin.shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^manual$"'
- name: check expected command was executed
ansible.builtin.assert:
that:
- 'alternative is changed'
- 'cmd.stdout == "dummy" ~ item'
- name: check that alternative has been updated
ansible.builtin.command: "grep -Pzq '/bin/dummy{{ item }}\\n{{ 60 + item|int }}' '{{ alternatives_dir }}/dummy'"
- name: update dummy priority
community.general.alternatives:
name: dummy
path: '/usr/bin/dummy{{ item }}'
link: /usr/bin/dummy
priority: '{{ 70 + item|int }}'
register: alternative
- name: check that alternative priority has been updated
ansible.builtin.command: "grep -Pzq '/bin/dummy{{ item }}\\n{{ 70 + item|int }}' '{{ alternatives_dir }}/dummy'"
- name: no change without priority
community.general.alternatives:
name: dummy
path: '/usr/bin/dummy{{ item }}'
link: /usr/bin/dummy
register: alternative
- name: check no change was triggered without priority
ansible.builtin.assert:
that:
- 'alternative is not changed'
- name: check that alternative priority has not been changed
ansible.builtin.command: "grep -Pzq '/bin/dummy{{ item }}\\n{{ 70 + item|int }}' '{{ alternatives_dir }}/dummy'"
@@ -0,0 +1,120 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# Add a few dummy alternatives with state = present and make sure that the
# group is in 'auto' mode and the highest priority alternative is selected.
- name: Add some dummy alternatives with state = present
community.general.alternatives:
name: dummy
path: "/usr/bin/dummy{{ item.n }}"
link: /usr/bin/dummy
priority: "{{ item.priority }}"
state: present
loop:
- { n: 1, priority: 50 }
- { n: 2, priority: 70 }
- { n: 3, priority: 25 }
- name: Ensure that the link group is in auto mode
ansible.builtin.shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^auto$"'
# Execute current selected 'dummy' and ensure it's the alternative we expect
- name: Execute the current dummy command
ansible.builtin.command: dummy
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy2"
# Add another alternative with state = 'selected' and make sure that
# this change results in the group being set to manual mode, and the
# new alternative being the selected one.
- name: Add another dummy alternative with state = selected
community.general.alternatives:
name: dummy
path: /usr/bin/dummy4
link: /usr/bin/dummy
priority: 10
state: selected
- name: Ensure that the link group is in manual mode
ansible.builtin.shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^manual$"'
- name: Execute the current dummy command
ansible.builtin.command: dummy
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy4"
# Set the currently selected alternative to state = 'present' (was previously
# selected), and ensure that this results in the group not being set to 'auto'
# mode, and the alternative is still selected.
- name: Set current selected dummy to state = present
community.general.alternatives:
name: dummy
path: /usr/bin/dummy4
link: /usr/bin/dummy
state: present
- name: Ensure that the link group is in auto mode
ansible.builtin.shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^manual$"'
- name: Execute the current dummy command
ansible.builtin.command: dummy
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy4"
# Set the currently selected alternative to state = 'auto' (was previously
# selected), and ensure that this results in the group being set to 'auto'
# mode, and the highest priority alternative is selected.
- name: Set current selected dummy to state = present
community.general.alternatives:
name: dummy
path: /usr/bin/dummy4
link: /usr/bin/dummy
state: auto
- name: Ensure that the link group is in auto mode
ansible.builtin.shell: 'head -n1 {{ alternatives_dir }}/dummy | grep "^auto$"'
- name: Execute the current dummy command
ansible.builtin.command: dummy
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy2"
# Remove an alternative with state = 'absent' and make sure that
# this change results in the alternative being removed.
- name: Remove best dummy alternative with state = absent
community.general.alternatives:
name: dummy
path: /usr/bin/dummy2
state: absent
- name: Ensure that the link group is in auto mode
ansible.builtin.command: 'grep "/usr/bin/dummy2" {{ alternatives_dir }}/dummy'
register: cmd
failed_when: cmd.rc == 0
- name: Execute the current dummy command
ansible.builtin.command: dummy
register: cmd
- name: Ensure that the expected command was executed
ansible.builtin.assert:
that:
- cmd.stdout == "dummy1"
@@ -0,0 +1,17 @@
{#
Copyright (c) Ansible Project
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
SPDX-License-Identifier: GPL-3.0-or-later
#}
{{ mode }}
/usr/bin/dummy
{% if with_alternatives %}
/usr/bin/dummy1
40
/usr/bin/dummy2
30
{% else %}
{% endif %}
@@ -0,0 +1,6 @@
#!/bin/sh
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
echo dummy{{ item }}
@@ -0,0 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
alternatives_dir: /var/lib/dpkg/alternatives/
alternatives_command: update-alternatives
@@ -0,0 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
alternatives_dir: /var/lib/rpm/alternatives/
alternatives_command: update-alternatives
@@ -0,0 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
alternatives_dir: /var/lib/alternatives/
alternatives_command: update-alternatives
@@ -0,0 +1,7 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
destructive
needs/root
@@ -0,0 +1,8 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
dependencies:
- setup_pkg_mgr
- setup_remote_tmp_dir
@@ -0,0 +1,92 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Install skiaparser;1
community.general.android_sdk:
accept_licenses: true
name: skiaparser;1
state: present
register: skiaparser_1_installed
- name: Install skiaparser;1 second time
community.general.android_sdk:
name: skiaparser;1
state: present
register: skiaparser_1_installed_2
- name: Stat skiaparser;1
ansible.builtin.stat:
path: "{{ android_sdk_location }}/skiaparser/1"
register: skiaparser_1_stat
- name: Delete skiaparser;1
community.general.android_sdk:
name: skiaparser;1
state: absent
register: skiaparser_1_deleted
- name: Delete skiaparser;1 second time
community.general.android_sdk:
name: skiaparser;1
state: absent
register: skiaparser_1_deleted_2
- name: Download old platform-tools
ansible.builtin.unarchive:
src: https://dl.google.com/android/repository/platform-tools_r27.0.0-linux.zip
remote_src: true
dest: "{{ android_sdk_location }}"
- name: Try installing platform-tools from sdkmanager
community.general.android_sdk:
name: platform-tools
accept_licenses: true
state: present
register: platform_tools_present
- name: Install (update) platform-tools
community.general.android_sdk:
name: platform-tools
state: latest
register: platform_tools_updated
- name: Install a package to a new root
community.general.android_sdk:
name: skiaparser;1
accept_licenses: true
state: present
sdk_root: "{{ remote_tmp_dir }}"
register: new_root_package
- name: Check package is installed
ansible.builtin.stat:
path: "{{ remote_tmp_dir }}/skiaparser/1"
register: new_root_package_stat
- name: Install a package from canary channel
community.general.android_sdk:
name: skiaparser;1
state: present
channel: canary
register: package_canary
- name: Run tests
ansible.builtin.assert:
that:
- skiaparser_1_stat.stat.exists
- skiaparser_1_installed is changed
- skiaparser_1_installed_2 is not changed
- skiaparser_1_deleted is changed
- skiaparser_1_deleted_2 is not changed
- platform_tools_present is not changed
- platform_tools_updated is changed
- new_root_package is changed
- new_root_package_stat.stat.exists
- package_canary is changed
@@ -0,0 +1,72 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Install sources;android-26 (FreeBSD)
community.general.android_sdk:
name: sources;android-26
accept_licenses: true
state: present
register: sources_android_26_installed
- name: Install sources;android-26 (FreeBSD)
community.general.android_sdk:
name: sources;android-26
state: present
register: sources_android_26_installed2
- name: Stat build-tools (FreeBSD)
ansible.builtin.stat:
path: "{{ android_sdk_location }}/sources/android-26"
register: sources_android_26
- name: Delete sources;android-26 (FreeBSD)
community.general.android_sdk:
name: sources;android-26
state: absent
register: sources_android_26_deleted
- name: Delete sources;android-26 second time (FreeBSD)
community.general.android_sdk:
name: sources;android-26
state: absent
register: sources_android_26_deleted2
- name: Install a package to a new root (FreeBSD)
community.general.android_sdk:
name: sources;android-26
accept_licenses: true
state: present
sdk_root: "{{ remote_tmp_dir }}"
register: new_root_package
- name: Check package is installed (FreeBSD)
ansible.builtin.stat:
path: "{{ remote_tmp_dir }}/sources/android-26"
register: new_root_package_stat
- name: Install a package from canary channel (FreeBSD)
community.general.android_sdk:
name: sources;android-26
accept_licenses: true
state: present
channel: canary
register: package_canary
- name: Run tests (FreeBSD)
ansible.builtin.assert:
that:
- sources_android_26.stat.exists
- sources_android_26_installed is changed
- sources_android_26_installed2 is not changed
- sources_android_26_deleted is changed
- sources_android_26_deleted2 is not changed
- new_root_package is changed
- new_root_package_stat.stat.exists
- package_canary is changed
@@ -0,0 +1,25 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Run android_sdk tests
environment:
PATH: '{{ ansible_facts.env.PATH }}:{{ android_sdk_location }}/cmdline-tools/latest/bin'
block:
- ansible.builtin.import_tasks: setup.yml
- name: Run default tests
ansible.builtin.import_tasks: default-tests.yml
when: ansible_facts.os_family != 'FreeBSD'
# Most of the important Android SDK packages are not available on FreeBSD (like, build-tools, platform-tools and so on),
# but at least some of the functionality can be tested (like, downloading sources)
- name: Run FreeBSD tests
ansible.builtin.import_tasks: freebsd-tests.yml
when: ansible_facts.os_family == 'FreeBSD'
@@ -0,0 +1,97 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Include OS-specific variables
ansible.builtin.include_vars: '{{ lookup("first_found", params) }}'
vars:
params:
files:
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_version }}.yml'
- '{{ ansible_facts.distribution }}-{{ ansible_facts.distribution_major_version }}.yml'
- '{{ ansible_facts.distribution }}.yml'
- '{{ ansible_facts.os_family }}.yml'
paths:
- '{{ role_path }}/vars'
- name: Install dependencies
become: true
ansible.builtin.package:
name:
- "{{ openjdk_pkg }}"
- unzip
state: present
when: ansible_facts.os_family != 'Darwin'
- name: Install dependencies (OSX)
block:
- name: Find brew binary
ansible.builtin.command: which brew
register: brew_which
- name: Get owner of brew binary
ansible.builtin.stat:
path: "{{ brew_which.stdout }}"
register: brew_stat
- name: "Install package"
community.general.homebrew:
name:
- "{{ openjdk_pkg }}"
- unzip
state: present
update_homebrew: false
become: true
become_user: "{{ brew_stat.stat.pw_name }}"
environment:
HOMEBREW_NO_AUTO_UPDATE: "True"
- name: Symlink java
become: true
ansible.builtin.file:
src: "{{ brew_prefix }}/opt/openjdk@17/libexec/openjdk.jdk"
dest: "/Library/Java/JavaVirtualMachines/openjdk-17.jdk"
state: link
vars:
brew_prefix: "{{ lookup('pipe', 'brew --prefix') }}"
when:
- ansible_facts.os_family == 'Darwin'
- name: Create Android SDK directory
ansible.builtin.file:
path: "{{ android_sdk_location }}"
state: directory
- name: Check that sdkmanager is installed
ansible.builtin.stat:
path: "{{ android_sdk_location }}/cmdline-tools/latest/bin/sdkmanager"
register: sdkmanager_installed
- name: Install Android command line tools
when: not sdkmanager_installed.stat.exists
block:
- name: Create Android SDK dir structure
ansible.builtin.file:
path: "{{ item.path }}"
state: "{{ item.state }}"
with_items:
- { path: "{{ android_cmdline_temp_dir }}", state: "directory" }
- { path: "{{ android_sdk_location }}/cmdline-tools/latest", state: "directory" }
- name: Download Android command line tools
ansible.builtin.unarchive:
src: "{{ commandline_tools_link }}"
dest: "{{ android_cmdline_temp_dir }}"
remote_src: true
creates: "{{ android_cmdline_temp_dir }}/cmdline-tools"
when: not sdkmanager_installed.stat.exists
- name: Fix directory structure
ansible.builtin.copy:
src: "{{ android_cmdline_temp_dir }}/cmdline-tools/"
dest: "{{ android_sdk_location }}/cmdline-tools/latest"
remote_src: true
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: openjdk17-jre-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: jre17-openjdk-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: openjdk@17
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: openjdk-17-jre-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: openjdk-17-jre-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: openjdk-21-jre-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: java-25-openjdk-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: java-21-openjdk-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: openjdk17-jre
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: java-21-openjdk-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: java-21-openjdk-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: java-17-openjdk-headless
@@ -0,0 +1,6 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
openjdk_pkg: java-17-openjdk-headless
@@ -0,0 +1,8 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
android_cmdline_temp_dir: "/tmp/cmdlinetools"
android_sdk_location: "/tmp/androidsdk"
commandline_tools_link: https://dl.google.com/android/repository/commandlinetools-linux-11076708_latest.zip
@@ -0,0 +1,7 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
destructive
context/controller # While this is not really true, this module mainly is run on the controller, *and* needs access to the ansible-galaxy CLI tool
@@ -0,0 +1,15 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
roles:
# Install a role from Ansible Galaxy.
- name: geerlingguy.java
version: 1.9.6
collections:
# Install a collection from Ansible Galaxy.
- name: geerlingguy.php_roles
version: 0.9.3
source: https://galaxy.ansible.com
@@ -0,0 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
dependencies:
- setup_remote_tmp_dir
@@ -0,0 +1,183 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
###################################################
- name: Make directory install_c
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/install_c"
state: directory
- name: Install collection netbox.netbox
community.general.ansible_galaxy_install:
type: collection
name: netbox.netbox
dest: "{{ remote_tmp_dir }}/install_c"
register: install_c0
- name: Assert collection netbox.netbox was installed
ansible.builtin.assert:
that:
- install_c0 is changed
- '"netbox.netbox" in install_c0.new_collections'
- name: Install collection netbox.netbox (again)
community.general.ansible_galaxy_install:
type: collection
name: netbox.netbox
dest: "{{ remote_tmp_dir }}/install_c"
register: install_c1
- name: Assert collection was not installed
ansible.builtin.assert:
that:
- install_c1 is not changed
###################################################
- name: Make directory install_r
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/install_r"
state: directory
- name: Install role ansistrano.deploy
community.general.ansible_galaxy_install:
type: role
name: ansistrano.deploy
dest: "{{ remote_tmp_dir }}/install_r"
register: install_r0
- name: Assert collection ansistrano.deploy was installed
ansible.builtin.assert:
that:
- install_r0 is changed
- '"ansistrano.deploy" in install_r0.new_roles'
- name: Install role ansistrano.deploy (again)
community.general.ansible_galaxy_install:
type: role
name: ansistrano.deploy
dest: "{{ remote_tmp_dir }}/install_r"
register: install_r1
- name: Assert role was not installed
ansible.builtin.assert:
that:
- install_r1 is not changed
###################################################
- name: Set requirements file path
ansible.builtin.set_fact:
reqs_file: '{{ remote_tmp_dir }}/reqs.yaml'
- name: Copy requirements file
ansible.builtin.copy:
src: 'files/test.yml'
dest: '{{ reqs_file }}'
- name: Install from requirements file
community.general.ansible_galaxy_install:
type: both
requirements_file: "{{ reqs_file }}"
register: install_rq0
ignore_errors: true
- name: Assert requirements file was installed
ansible.builtin.assert:
that:
- install_rq0 is changed
- '"geerlingguy.java" in install_rq0.new_roles'
- '"geerlingguy.php_roles" in install_rq0.new_collections'
- name: Install from requirements file (again)
community.general.ansible_galaxy_install:
type: both
requirements_file: "{{ reqs_file }}"
register: install_rq1
ignore_errors: true
- name: Assert requirements file was not installed
ansible.builtin.assert:
that:
- install_rq1 is not changed
###################################################
- name: Make directory upgrade_c
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/upgrade_c"
state: directory
- name: Install collection netbox.netbox 3.17.0
community.general.ansible_galaxy_install:
type: collection
name: netbox.netbox:3.17.0
dest: "{{ remote_tmp_dir }}/upgrade_c"
register: upgrade_c0
- name: Assert collection netbox.netbox was installed
ansible.builtin.assert:
that:
- upgrade_c0 is changed
- '"netbox.netbox" in upgrade_c0.new_collections'
- name: Upgrade collection netbox.netbox
community.general.ansible_galaxy_install:
state: latest
type: collection
name: netbox.netbox
dest: "{{ remote_tmp_dir }}/upgrade_c"
register: upgrade_c1
- name: Upgrade collection netbox.netbox (again)
community.general.ansible_galaxy_install:
state: latest
type: collection
name: netbox.netbox
dest: "{{ remote_tmp_dir }}/upgrade_c"
register: upgrade_c2
- name: Assert collection was not installed
ansible.builtin.assert:
that:
- upgrade_c1 is changed
- upgrade_c2 is not changed
###################################################
- name: Find ansible-galaxy executable path
ansible.builtin.command: which ansible-galaxy
register: galaxy_which
changed_when: false
- name: Make directory exec_c
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/exec_c"
state: directory
- name: Install collection using explicit executable path
community.general.ansible_galaxy_install:
type: collection
name: netbox.netbox
dest: "{{ remote_tmp_dir }}/exec_c"
executable: "{{ galaxy_which.stdout }}"
register: exec_c0
- name: Assert collection was installed using explicit executable
ansible.builtin.assert:
that:
- exec_c0 is changed
- '"netbox.netbox" in exec_c0.new_collections'
- exec_c0.executable == galaxy_which.stdout
- name: Fail to install collection using bad executable path
community.general.ansible_galaxy_install:
type: collection
name: netbox.netbox
dest: "{{ remote_tmp_dir }}/exec_c"
executable: /nonexistent/ansible-galaxy
register: exec_c_fail
ignore_errors: true
- name: Assert bad executable caused failure
ansible.builtin.assert:
that:
- exec_c_fail is failed
@@ -0,0 +1,6 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
destructive
@@ -0,0 +1,8 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
dependencies:
- setup_remote_constraints
- setup_apache2
@@ -0,0 +1,253 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- ansible.builtin.meta: end_play
when: ansible_facts.os_family not in ['Debian', 'Suse']
- name: Enable mod_proxy
community.general.apache2_module:
state: present
name: "{{ item }}"
loop:
- status
- proxy
- proxy_http
- proxy_balancer
- lbmethod_byrequests
- name: Add port 81
ansible.builtin.lineinfile:
path: "/etc/apache2/{{ 'ports.conf' if ansible_facts.os_family == 'Debian' else 'listen.conf' }}"
line: Listen 81
- name: Set up virtual host
ansible.builtin.copy:
dest: "/etc/apache2/{{ 'sites-available' if ansible_facts.os_family == 'Debian' else 'vhosts.d' }}/000-apache2_mod_proxy-test.conf"
content: |
<VirtualHost *:81>
<Proxy balancer://mycluster>
BalancerMember http://127.0.0.1:8080
BalancerMember http://127.0.0.1:8081
</Proxy>
<IfModule mod_evasive20.c>
DOSBlockingPeriod 0
DOSWhiteList 127.0.0.1
DOSWhiteList ::1
</IfModule>
<Location "/app/">
ProxyPreserveHost On
ProxyPass balancer://mycluster/
ProxyPassReverse balancer://mycluster/
</Location>
<Location "/balancer-manager">
SetHandler balancer-manager
Require all granted
</Location>
</VirtualHost>
- name: Enable virtual host
ansible.builtin.file:
src: /etc/apache2/sites-available/000-apache2_mod_proxy-test.conf
dest: /etc/apache2/sites-enabled/000-apache2_mod_proxy-test.conf
owner: root
group: root
state: link
when: ansible_facts.os_family not in ['Suse']
- name: Restart Apache
ansible.builtin.service:
name: apache2
state: restarted
- name: Install BeautifulSoup
ansible.builtin.pip:
name: BeautifulSoup4
extra_args: "-c {{ remote_constraints }}"
- name: Get all current balancer pool members attributes
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
register: result
- ansible.builtin.assert:
that:
- result is not changed
- result.members | length == 2
- result.members[0].port in ["8080", "8081"]
- result.members[0].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[0].host == "127.0.0.1"
- result.members[0].path is none
- result.members[0].protocol == "http"
- result.members[1].port in ["8080", "8081"]
- result.members[1].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[1].host == "127.0.0.1"
- result.members[1].path is none
- result.members[1].protocol == "http"
- name: Enable member
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
member_host: 127.0.0.1
state: present
register: result
- ansible.builtin.assert:
that:
- result is not changed
- name: Get all current balancer pool members attributes
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
register: result
- ansible.builtin.assert:
that:
- result is not changed
- result.members | length == 2
- result.members[0].port in ["8080", "8081"]
- result.members[0].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[0].host == "127.0.0.1"
- result.members[0].path is none
- result.members[0].protocol == "http"
- result.members[0].status.disabled == false
- result.members[0].status.drained == false
- result.members[0].status.hot_standby == false
- result.members[0].status.ignore_errors == false
- result.members[1].port in ["8080", "8081"]
- result.members[1].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[1].host == "127.0.0.1"
- result.members[1].path is none
- result.members[1].protocol == "http"
- result.members[1].status.disabled == false
- result.members[1].status.drained == false
- result.members[1].status.hot_standby == false
- result.members[1].status.ignore_errors == false
- name: Drain member
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
member_host: 127.0.0.1
state: drained
register: result
- ansible.builtin.assert:
that:
- result is changed
# Note that since both members are on the same host, this always affects **both** members!
- name: Get all current balancer pool members attributes
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
register: result
- ansible.builtin.assert:
that:
- result is not changed
- result.members | length == 2
- result.members[0].port in ["8080", "8081"]
- result.members[0].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[0].host == "127.0.0.1"
- result.members[0].path is none
- result.members[0].protocol == "http"
- result.members[0].status.disabled == false
- result.members[0].status.drained == true
- result.members[0].status.hot_standby == false
- result.members[0].status.ignore_errors == false
- result.members[1].port in ["8080", "8081"]
- result.members[1].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[1].host == "127.0.0.1"
- result.members[1].path is none
- result.members[1].protocol == "http"
- result.members[1].status.disabled == false
- result.members[1].status.drained == true
- result.members[1].status.hot_standby == false
- result.members[1].status.ignore_errors == false
- name: Disable member
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
member_host: 127.0.0.1
state: absent
register: result
- ansible.builtin.assert:
that:
- result is changed
- name: Get all current balancer pool members attributes
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
register: result
- ansible.builtin.assert:
that:
- result is not changed
- result.members | length == 2
- result.members[0].port in ["8080", "8081"]
- result.members[0].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[0].host == "127.0.0.1"
- result.members[0].path is none
- result.members[0].protocol == "http"
- result.members[0].status.disabled == true
- result.members[0].status.drained == false
- result.members[0].status.hot_standby == false
- result.members[0].status.ignore_errors == false
- result.members[1].port in ["8080", "8081"]
- result.members[1].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[1].host == "127.0.0.1"
- result.members[1].path is none
- result.members[1].protocol == "http"
- result.members[1].status.disabled == true
- result.members[1].status.drained == false
- result.members[1].status.hot_standby == false
- result.members[1].status.ignore_errors == false
- name: Enable member
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
member_host: 127.0.0.1
state: present
register: result
- ansible.builtin.assert:
that:
- result is changed
- name: Get all current balancer pool members attributes
community.general.apache2_mod_proxy:
balancer_vhost: localhost:81
register: result
- ansible.builtin.assert:
that:
- result is not changed
- result.members | length == 2
- result.members[0].port in ["8080", "8081"]
- result.members[0].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[0].host == "127.0.0.1"
- result.members[0].path is none
- result.members[0].protocol == "http"
- result.members[0].status.disabled == false
- result.members[0].status.drained == false
- result.members[0].status.hot_standby == false
- result.members[0].status.ignore_errors == false
- result.members[1].port in ["8080", "8081"]
- result.members[1].balancer_url == "http://localhost:81/balancer-manager/"
- result.members[1].host == "127.0.0.1"
- result.members[1].path is none
- result.members[1].protocol == "http"
- result.members[1].status.disabled == false
- result.members[1].status.drained == false
- result.members[1].status.hot_standby == false
- result.members[1].status.ignore_errors == false
@@ -0,0 +1,6 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
destructive
@@ -0,0 +1,7 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
dependencies:
- setup_apache2
@@ -0,0 +1,97 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# This test represents the behavior described in
# https://github.com/ansible-collections/community.general/issues/3510:
# with ignore_configcheck, disabling a module must not be skipped just because
# apache2ctl -M fails, for a reason unrelated to the module being changed.
- name: enable headers module, recording its original state
community.general.apache2_module:
name: headers
state: present
register: headers_first_enable
- name: disable rewrite module, recording its original state
community.general.apache2_module:
name: rewrite
state: absent
force: true
register: rewrite_first_disable
- name: add a site that requires rewrite, breaking the config for reasons unrelated to headers
ansible.builtin.copy:
dest: /etc/apache2/sites-enabled/999-3510-broken.conf
content: |
RewriteEngine On
mode: "0644"
- name: confirm the config is indeed broken
ansible.builtin.command: apache2ctl -M
register: broken_check_3510
failed_when: false
changed_when: false
- name: sanity check that the injected site really broke the config
ansible.builtin.assert:
that:
- broken_check_3510.rc != 0
- name: disable headers module while the config is broken, in check mode
community.general.apache2_module:
name: headers
state: absent
ignore_configcheck: true
check_mode: true
register: disable_headers_broken_config_check
- name: disable headers module while the config is broken for an unrelated reason
community.general.apache2_module:
name: headers
state: absent
ignore_configcheck: true
register: disable_headers_broken_config
- name: check whether headers is still enabled
ansible.builtin.stat:
path: /etc/apache2/mods-enabled/headers.load
register: headers_load_after_disable
- name: ensure disabling headers took effect despite the unrelated broken config
ansible.builtin.assert:
that:
- disable_headers_broken_config_check is changed
- disable_headers_broken_config is succeeded
- disable_headers_broken_config is changed
- not headers_load_after_disable.stat.exists
- name: disable headers module again, idempotency check
community.general.apache2_module:
name: headers
state: absent
ignore_configcheck: true
register: disable_headers_broken_config_again
- name: ensure idempotency holds despite the unrelated broken config
ansible.builtin.assert:
that:
- disable_headers_broken_config_again is succeeded
- disable_headers_broken_config_again is not changed
- name: remove the injected broken site
ansible.builtin.file:
path: /etc/apache2/sites-enabled/999-3510-broken.conf
state: absent
- name: restore headers module to its original state
community.general.apache2_module:
name: headers
state: present
when: headers_first_enable is not changed
- name: restore rewrite module to its original state
community.general.apache2_module:
name: rewrite
state: present
when: rewrite_first_disable is changed
@@ -0,0 +1,82 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# This test represents the behavior described in
# https://github.com/ansible-collections/community.general/issues/4592:
# with ignore_configcheck, a module change that itself succeeds (a2enmod/a2dismod
# returns success) must not be reported as failed just because apache2ctl -M keeps
# failing afterwards, for a reason unrelated to the module being changed.
- name: disable headers module, recording its original state
community.general.apache2_module:
name: headers
state: absent
register: headers_first_disable
- name: disable rewrite module, recording its original state
community.general.apache2_module:
name: rewrite
state: absent
force: true
register: rewrite_first_disable
- name: add a site that requires rewrite, breaking the config for reasons unrelated to headers
ansible.builtin.copy:
dest: /etc/apache2/sites-enabled/999-4592-broken.conf
content: |
RewriteEngine On
mode: "0644"
- name: confirm the config is indeed broken
ansible.builtin.command: apache2ctl -M
register: broken_check
failed_when: false
changed_when: false
- name: sanity check that the injected site really broke the config
ansible.builtin.assert:
that:
- broken_check.rc != 0
- name: enable headers module while the config is broken for an unrelated reason
community.general.apache2_module:
name: headers
state: present
ignore_configcheck: true
register: enable_headers_broken_config
- name: ensure enabling headers succeeded despite the unrelated broken config
ansible.builtin.assert:
that:
- enable_headers_broken_config is succeeded
- enable_headers_broken_config is changed
- name: enable headers module again, idempotency check
community.general.apache2_module:
name: headers
state: present
ignore_configcheck: true
register: enable_headers_broken_config_again
- name: ensure idempotency holds despite the unrelated broken config
ansible.builtin.assert:
that:
- enable_headers_broken_config_again is succeeded
- enable_headers_broken_config_again is not changed
- name: remove the injected broken site
ansible.builtin.file:
path: /etc/apache2/sites-enabled/999-4592-broken.conf
state: absent
- name: restore headers module to its original state
community.general.apache2_module:
name: headers
state: "{{ 'present' if headers_first_disable is changed else 'absent' }}"
- name: restore rewrite module to its original state
community.general.apache2_module:
name: rewrite
state: present
when: rewrite_first_disable is changed
@@ -0,0 +1,47 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# This test represent the misleading behavior of the following issue: https://github.com/ansible-collections/community.general/issues/635
- name: Disable MPM event module
community.general.apache2_module:
name: "{{ item.module}}"
state: "{{ item.state}}"
ignore_configcheck: true
register: disable_mpm_modules
with_items:
- { module: mpm_event, state: absent }
- { module: mpm_prefork, state: present }
- ansible.builtin.assert:
that:
- "'warnings' in disable_mpm_modules"
- disable_mpm_modules["warnings"] == [
"No MPM module loaded! apache2 reload AND other module actions will fail if no MPM module is loaded immediately.",
"No MPM module loaded! apache2 reload AND other module actions will fail if no MPM module is loaded immediately."
]
- name: Enable MPM event module - Revert previous change
community.general.apache2_module:
name: "{{ item.module}}"
state: "{{ item.state}}"
ignore_configcheck: true
register: disable_mpm_modules
with_items:
- { module: mpm_prefork, state: absent }
- { module: mpm_event, state: present }
- name: Disable MPM event module
community.general.apache2_module:
name: "{{ item.module}}"
state: "{{ item.state}}"
ignore_configcheck: true
warn_mpm_absent: false
register: disable_mpm_modules
with_items:
- { module: mpm_event, state: absent }
- { module: mpm_prefork, state: present }
- ansible.builtin.assert:
that:
- "'warnings' not in disable_mpm_modules"
@@ -0,0 +1,212 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: disable userdir module
community.general.apache2_module:
name: userdir
state: absent
register: userdir_first_disable
- name: disable userdir module, second run
community.general.apache2_module:
name: userdir
state: absent
register: disable
- name: ensure community.general.apache2_module is idempotent
ansible.builtin.assert:
that:
- disable is not changed
- name: enable userdir module
community.general.apache2_module:
name: userdir
state: present
register: enable
- name: ensure changed on successful enable
ansible.builtin.assert:
that:
- enable is changed
- name: enable userdir module, second run
community.general.apache2_module:
name: userdir
state: present
register: enabletwo
- name: ensure community.general.apache2_module is idempotent
ansible.builtin.assert:
that:
- 'enabletwo is not changed'
- name: disable userdir module, final run
community.general.apache2_module:
name: userdir
state: absent
register: disablefinal
- name: ensure changed on successful disable
ansible.builtin.assert:
that:
- 'disablefinal is changed'
- name: set userdir to original state
community.general.apache2_module:
name: userdir
state: present
when: userdir_first_disable is changed
- name: ensure autoindex enabled
community.general.apache2_module:
name: autoindex
state: present
- name: Debian/Ubuntu specific tests
when: "ansible_facts.os_family == 'Debian'"
block:
- name: force disable of autoindex # bug #2499
community.general.apache2_module:
name: autoindex
state: absent
force: true
- name: re-enable autoindex
community.general.apache2_module:
name: autoindex
state: present
# mod_evasive is enabled by default upon the installation, so disable first and enable second, to preserve the config
- name: disable evasive module
community.general.apache2_module:
name: evasive
state: absent
- name: enable evasive module, test https://github.com/ansible/ansible/issues/22635
community.general.apache2_module:
name: evasive
state: present
when:
# TODO: fix for Debian 13 (Trixie)!
- ansible_facts.distribution != 'Debian' or ansible_facts.distribution_major_version is version('13', '<')
# TODO: fix for Ubuntu 26.04!
- ansible_facts.distribution != 'Ubuntu' or ansible_facts.distribution_major_version is version('26', '<')
- name: use identifier to enable module, fix for https://github.com/ansible/ansible/issues/33669
community.general.apache2_module:
name: dump_io
state: present
ignore_errors: true
register: enable_dumpio_wrong
- name: disable dump_io
community.general.apache2_module:
name: dump_io
identifier: dumpio_module
state: absent
- name: use identifier to enable module, fix for https://github.com/ansible/ansible/issues/33669
community.general.apache2_module:
name: dump_io
identifier: dumpio_module
state: present
register: enable_dumpio_correct_1
- name: ensure idempotency with identifier
community.general.apache2_module:
name: dump_io
identifier: dumpio_module
state: present
register: enable_dumpio_correct_2
- name: disable dump_io
community.general.apache2_module:
name: dump_io
identifier: dumpio_module
state: absent
- ansible.builtin.assert:
that:
- enable_dumpio_wrong is failed
- enable_dumpio_correct_1 is changed
- enable_dumpio_correct_2 is not changed
- name: disable mpm modules
community.general.apache2_module:
name: "{{ item }}"
state: absent
ignore_configcheck: true
with_items:
- mpm_worker
- mpm_event
- mpm_prefork
- name: enabled mpm_event
community.general.apache2_module:
name: mpm_event
state: present
ignore_configcheck: true
register: enabledmpmevent
- name: ensure changed mpm_event
ansible.builtin.assert:
that:
- 'enabledmpmevent is changed'
- name: switch between mpm_event and mpm_worker
community.general.apache2_module:
name: "{{ item.name }}"
state: "{{ item.state }}"
ignore_configcheck: true
with_items:
- name: mpm_event
state: absent
- name: mpm_worker
state: present
- name: ensure mpm_worker is already enabled
community.general.apache2_module:
name: mpm_worker
state: present
register: enabledmpmworker
- name: ensure mpm_worker unchanged
ansible.builtin.assert:
that:
- 'enabledmpmworker is not changed'
- name: try to disable all mpm modules with configcheck
community.general.apache2_module:
name: "{{item}}"
state: absent
with_items:
- mpm_worker
- mpm_event
- mpm_prefork
ignore_errors: true
register: remove_with_configcheck
- name: ensure configcheck fails task with when run without mpm modules
ansible.builtin.assert:
that:
- item is failed
with_items: "{{ remove_with_configcheck.results }}"
- name: try to disable all mpm modules without configcheck
community.general.apache2_module:
name: "{{item}}"
state: absent
ignore_configcheck: true
with_items:
- mpm_worker
- mpm_event
- mpm_prefork
- name: enabled mpm_event to restore previous state
community.general.apache2_module:
name: mpm_event
state: present
ignore_configcheck: true
register: enabledmpmevent
@@ -0,0 +1,46 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: test apache2_module
when: ansible_facts.os_family in ['Debian', 'Suse']
# CentOS/RHEL does not have a2enmod/a2dismod
block:
- name: get list of enabled modules
ansible.builtin.shell: apache2ctl -M | sort
register: modules_before
- name: include only on supported systems
ansible.builtin.include_tasks: actualtest.yml
always:
- name: get list of enabled modules
ansible.builtin.shell: apache2ctl -M | sort
register: modules_after
- name: modules_before
ansible.builtin.debug:
var: modules_before
- name: modules_after
ansible.builtin.debug:
var: modules_after
- name: ensure that all test modules are disabled again
ansible.builtin.assert:
that: modules_before.stdout == modules_after.stdout
- name: Debian-only tests
when: ansible_facts.os_family == 'Debian'
# Suse has mpm_event module compiled within the base apache2,
# and its sites-enabled layout differs from Debian's
block:
- name: include misleading warning test
ansible.builtin.include_tasks: 635-apache2-misleading-warning.yml
- name: include unrelated broken config test
ansible.builtin.include_tasks: 4592-ignore-configcheck-unrelated-broken-config.yml
- name: include disable with broken config test
ansible.builtin.include_tasks: 3510-ignore-configcheck-disable-broken-config.yml
@@ -0,0 +1,11 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/2
needs/root
destructive
skip/macos
skip/freebsd
skip/rhel
skip/ubuntu
@@ -0,0 +1,241 @@
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) 2024, Max Maxopoly <max@dermax.org>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Run apk tests on Alpine
when: ansible_facts.distribution in ['Alpine']
block:
- name: Ensure vim is not installed
community.general.apk:
name: vim
state: absent
- name: Install vim
community.general.apk:
name: vim
state: present
register: results
- name: Ensure vim was installed
ansible.builtin.assert:
that:
- results is changed
- (results.packages | length) >= 1 # vim has dependencies, so depending on the base image this number may vary
- name: Install vim again
community.general.apk:
name: vim
state: present
register: results
- name: Ensure vim was not installed again
ansible.builtin.assert:
that:
- results is not changed
- (results.packages | default([]) | length) == 0
- name: Ensure vim is not installed
community.general.apk:
name: vim
state: absent
register: results
- name: Ensure vim was uninstalled
ansible.builtin.assert:
that:
- results is changed
- (results.packages | length) >= 1
- name: Install vim without cache
community.general.apk:
name: vim
state: present
no_cache: true
register: results
- name: Ensure vim was installed without cache
ansible.builtin.assert:
that:
- results is changed
- name: Install vim again without cache
community.general.apk:
name: vim
state: present
no_cache: true
register: results
- name: Ensure vim was not installed again without cache
ansible.builtin.assert:
that:
- results is not changed
- (results.packages | default([]) | length) == 0
- name: Ensure a bunch of packages aren't installed
community.general.apk:
name:
- less
- nano
- vim
state: absent
- name: Install a bunch of packages
community.general.apk:
name:
- less
- nano
- vim
- bash
- bash-completion
- bash-completion-doc
- zsh
- zsh-calendar
- zsh-completions
- zsh-doc
state: present
register: results
- name: Ensure a bunch of packages were installed
ansible.builtin.assert:
that:
- results is changed
- (results.packages | length) >= 10
- name: Install a bunch of packages again
community.general.apk:
name:
- less
- nano
- vim
state: present
register: results
- name: Ensure a bunch of packages were not installed again
ansible.builtin.assert:
that:
- results is not changed
- (results.packages | default([]) | length) == 0
- name: Ensure a bunch of packages are not installed
community.general.apk:
name:
- less
- nano
- vim
state: absent
register: results
- name: Ensure a bunch of packages were uninstalled
ansible.builtin.assert:
that:
- results is changed
- (results.packages | length) >= 3
- name: Install a bunch of packages without cache
community.general.apk:
name:
- less
- nano
- vim
state: present
no_cache: true
register: results
- name: Ensure a bunch of packages were installed without cache
ansible.builtin.assert:
that:
- results is changed
- name: Install a bunch of packages again without cache
community.general.apk:
name:
- less
- nano
- vim
state: present
no_cache: true
register: results
- name: Ensure a bunch of packages were not installed again without cache
ansible.builtin.assert:
that:
- results is not changed
- (results.packages | default([]) | length) == 0
- name: Install package with empty name
community.general.apk:
name: ""
register: result_empty
ignore_errors: true
- name: Assert failure due to empty package name
ansible.builtin.assert:
that:
- result_empty is failed
- "'Package name(s) cannot be empty or whitespace-only' == result_empty.msg"
- name: Install package name with only spaces
community.general.apk:
name: [" "]
register: result_spaces
ignore_errors: true
- name: Assert failure due to whitespace-only package name
ansible.builtin.assert:
that:
- result_spaces is failed
- "'Package name(s) cannot be empty or whitespace-only' == result_spaces.msg"
- name: Do not accept list with valid and empty string
community.general.apk:
name: ["busybox", ""]
register: result_invalid_mixed
ignore_errors: true
- name: Assert failure with mixed package list
ansible.builtin.assert:
that:
- result_invalid_mixed is failed
- "'Package name(s) cannot be empty or whitespace-only' == result_invalid_mixed.msg"
- name: Reject package name list with multiple empty/whitespace-only strings
community.general.apk:
name: ["", " "]
register: result_multiple_empty
ignore_errors: true
- name: Assert failure due to all package names being empty or whitespace
ansible.builtin.assert:
that:
- result_multiple_empty is failed
- "'Package name(s) cannot be empty or whitespace-only' == result_multiple_empty.msg"
- name: Reject empty package name with update_cache parameter
community.general.apk:
name: ""
update_cache: true
register: result_empty_package_with_update_cache
ignore_errors: true
- name: Assert failure due to all package names being empty or whitespace
ansible.builtin.assert:
that:
- result_empty_package_with_update_cache is failed
- "'Package name(s) cannot be empty or whitespace-only' == result_empty_package_with_update_cache.msg"
- name: Install package with a missing world file
community.general.apk:
name: busybox
world: /nonexistent/world
register: result_missing_world
ignore_errors: true
- name: Assert failure due to missing world file
ansible.builtin.assert:
that:
- result_missing_world is failed
- "'Cannot read world file /nonexistent/world' in result_missing_world.msg"
@@ -0,0 +1,7 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/2
needs/root
destructive
@@ -0,0 +1,5 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
bar.txt
@@ -0,0 +1,5 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
foo.txt
@@ -0,0 +1,8 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
dependencies:
- setup_pkg_mgr
- setup_remote_tmp_dir
@@ -0,0 +1,116 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Test code for the archive module.
# Copyright (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# Make sure we start fresh
# Test setup
- name: prep our files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{remote_tmp_dir}}/{{ item }}"
with_items:
- foo.txt
- bar.txt
- empty.txt
- sub
- sub/subfile.txt
# Run twice without lzma backport installed, to make sure it does not crash
- name: Archive - pre-test - first run
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_pretest_1.tar"
format: "tar"
register: pretest_1
- name: Archive - pre-test - second run
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_pretest_1.tar"
format: "tar"
register: pretest_2
- name: Archive - validate pre-test
ansible.builtin.assert:
that:
- pretest_1 is changed
- pretest_2 is not changed
# Install dependencies
- name: Ensure zip is present to create test archive (yum)
ansible.builtin.dnf:
name: zip
state: latest
when: ansible_facts.pkg_mgr == 'yum'
- name: Ensure zip is present to create test archive (apt)
ansible.builtin.apt:
name: zip
state: latest
when: ansible_facts.pkg_mgr == 'apt'
- name: Ensure zstandard Python package is present for zstd tests
ansible.builtin.pip:
name: zstandard
state: latest
- name: Define formats to test
ansible.builtin.set_fact:
formats:
- tar
- zip
- gz
- bz2
- xz
- zstd
# Run tests
- name: Run core tests
ansible.builtin.include_tasks:
file: ../tests/core.yml
loop: "{{ formats }}"
loop_control:
loop_var: format
- name: Run exclusions tests
ansible.builtin.include_tasks:
file: ../tests/exclusions.yml
loop: "{{ formats }}"
loop_control:
loop_var: format
- name: Run remove tests
ansible.builtin.include_tasks:
file: ../tests/remove.yml
loop: "{{ formats }}"
loop_control:
loop_var: format
- name: Run broken link tests
ansible.builtin.include_tasks:
file: ../tests/broken-link.yml
loop: "{{ formats }}"
loop_control:
loop_var: format
- name: Run Idempotency tests
ansible.builtin.include_tasks:
file: ../tests/idempotency.yml
loop: "{{ formats }}"
loop_control:
loop_var: format
- name: Run dest in path tests
ansible.builtin.include_tasks:
file: ../tests/dest-in-path.yml
loop: "{{ formats }}"
loop_control:
loop_var: format
@@ -0,0 +1,35 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- name: Create link - broken link ({{ format }})
ansible.builtin.file:
src: /nowhere
dest: "{{ remote_tmp_dir }}/nowhere.txt"
state: link
force: true
- name: Archive - broken link ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_broken_link.{{ format }}"
format: "{{ format }}"
- name: Verify archive exists - broken link ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_broken_link.{{ format }}"
state: file
- name: Remove archive - broken link ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_broken_link.{{ format }}"
state: absent
- name: Remove link - broken link ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/nowhere.txt"
state: absent
# 'zip' does not support symlink's
when: format != 'zip'
@@ -0,0 +1,178 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Test code for the archive module.
# Copyright (c) 2017, Abhijeet Kasurde <akasurde@redhat.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# Make sure we start fresh
# Core functionality tests
- name: Archive - no options ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_no_opts.{{ format }}"
format: "{{ format }}"
register: archive_no_options
- name: Verify that archive exists - no options ({{ format }})
ansible.builtin.file:
path: "{{remote_tmp_dir}}/archive_no_opts.{{ format }}"
state: file
- name: Verify that archive result is changed and includes all files - no options ({{ format }})
ansible.builtin.assert:
that:
- archive_no_options is changed
- "archive_no_options.dest_state == 'archive'"
- "archive_no_options.archived | length == 3"
- name: Remove the archive - no options ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_no_options.{{ format }}"
state: absent
- name: Archive - file options ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_file_options.{{ format }}"
format: "{{ format }}"
mode: "u+rwX,g-rwx,o-rwx"
register: archive_file_options
- name: Retrieve archive file information - file options ({{ format }})
ansible.builtin.stat:
path: "{{ remote_tmp_dir }}/archive_file_options.{{ format }}"
register: archive_file_options_stat
- name: Test that the file modes were changed
ansible.builtin.assert:
that:
- archive_file_options_stat is not changed
- "archive_file_options.mode == '0600'"
- "archive_file_options.archived | length == 3"
- name: Remove the archive - file options ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_file_options.{{ format }}"
state: absent
- name: Archive - non-ascii ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_nonascii_くらとみ.{{ format }}"
format: "{{ format }}"
register: archive_nonascii
- name: Retrieve archive file information - non-ascii ({{ format }})
ansible.builtin.stat:
path: "{{ remote_tmp_dir }}/archive_nonascii_くらとみ.{{ format }}"
register: archive_nonascii_stat
- name: Test that archive exists - non-ascii ({{ format }})
ansible.builtin.assert:
that:
- archive_nonascii is changed
- archive_nonascii_stat.stat.exists == true
- name: Remove the archive - non-ascii ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_nonascii_くらとみ.{{ format }}"
state: absent
- name: Archive - single target ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/foo.txt"
dest: "{{ remote_tmp_dir }}/archive_single_target.{{ format }}"
format: "{{ format }}"
register: archive_single_target
- name: Assert archive has correct state - single target ({{ format }})
ansible.builtin.assert:
that:
- archive_single_target.dest_state == state_map[format]
vars:
state_map:
tar: archive
zip: archive
gz: compress
bz2: compress
xz: compress
zstd: compress
- block:
- name: Retrieve contents of archive - single target ({{ format }})
ansible.builtin.unarchive:
src: "{{ remote_tmp_dir }}/archive_single_target.{{ format }}"
dest: .
list_files: true
check_mode: true
ignore_errors: true
register: archive_single_target_contents
- name: Assert that file names are preserved - single target ({{ format }})
ansible.builtin.assert:
that:
- "'oo.txt' not in archive_single_target_contents.files"
- "'foo.txt' in archive_single_target_contents.files"
# ``unarchive`` fails for RHEL and FreeBSD on ansible 2.x
when: archive_single_target_contents is success and archive_single_target_contents is not skipped
when: "format == 'zip'"
- name: Remove archive - single target ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_single_target.{{ format }}"
state: absent
- name: Archive - path list ({{ format }})
community.general.archive:
path:
- "{{ remote_tmp_dir }}/empty.txt"
- "{{ remote_tmp_dir }}/foo.txt"
- "{{ remote_tmp_dir }}/bar.txt"
dest: "{{ remote_tmp_dir }}/archive_path_list.{{ format }}"
format: "{{ format }}"
register: archive_path_list
- name: Verify that archive exists - path list ({{ format }})
ansible.builtin.file:
path: "{{remote_tmp_dir}}/archive_path_list.{{ format }}"
state: file
- name: Assert that archive contains all files - path list ({{ format }})
ansible.builtin.assert:
that:
- archive_path_list is changed
- "archive_path_list.archived | length == 3"
- name: Remove archive - path list ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_path_list.{{ format }}"
state: absent
- name: Archive - missing paths ({{ format }})
community.general.archive:
path:
- "{{ remote_tmp_dir }}/*.txt"
- "{{ remote_tmp_dir }}/dne.txt"
exclude_path: "{{ remote_tmp_dir }}/foo.txt"
dest: "{{ remote_tmp_dir }}/archive_missing_paths.{{ format }}"
format: "{{ format }}"
register: archive_missing_paths
- name: Assert that incomplete archive has incomplete state - missing paths ({{ format }})
ansible.builtin.assert:
that:
- archive_missing_paths is changed
- "archive_missing_paths.dest_state == 'incomplete'"
- "(remote_tmp_dir ~ '/dne.txt') in archive_missing_paths.missing"
- "(remote_tmp_dir ~ '/foo.txt') not in archive_missing_paths.missing"
- name: Remove archive - missing paths ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_missing_paths.{{ format }}"
state: absent
@@ -0,0 +1,49 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Set paths - dest in path ({{ format }})
ansible.builtin.set_fact:
dest_in_path_src: "{{ remote_tmp_dir }}/dest_in_path_{{ format }}"
dest_in_path_dest: "{{ remote_tmp_dir }}/dest_in_path_{{ format }}/archive.{{ format }}"
- name: Create source directory - dest in path ({{ format }})
ansible.builtin.file:
path: "{{ dest_in_path_src }}"
state: directory
- name: Copy files into source directory - dest in path ({{ format }})
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ dest_in_path_src }}/{{ item }}"
loop:
- foo.txt
- bar.txt
- name: Archive - dest in path ({{ format }})
community.general.archive:
path: "{{ dest_in_path_src }}"
dest: "{{ dest_in_path_dest }}"
format: "{{ format }}"
register: dest_in_path_first
- name: Archive again - dest in path ({{ format }})
community.general.archive:
path: "{{ dest_in_path_src }}"
dest: "{{ dest_in_path_dest }}"
format: "{{ format }}"
register: dest_in_path_second
- name: Assert that the archive does not contain itself - dest in path ({{ format }})
ansible.builtin.assert:
that:
- dest_in_path_first is changed
- dest_in_path_dest not in dest_in_path_first.archived
- dest_in_path_second is not changed
- dest_in_path_dest not in dest_in_path_second.archived
- name: Remove source directory - dest in path ({{ format }})
ansible.builtin.file:
path: "{{ dest_in_path_src }}"
state: absent
@@ -0,0 +1,44 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Archive - exclusion patterns ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_exclusion_patterns.{{ format }}"
format: "{{ format }}"
exclusion_patterns: b?r.*
register: archive_exclusion_patterns
- name: Assert that only included files are archived - exclusion patterns ({{ format }})
ansible.builtin.assert:
that:
- archive_exclusion_patterns is changed
- "'bar.txt' not in archive_exclusion_patterns.archived"
- name: Remove archive - exclusion patterns ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_exclusion_patterns.{{ format }}"
state: absent
- name: Archive - exclude path ({{ format }})
community.general.archive:
path:
- "{{ remote_tmp_dir }}/sub/subfile.txt"
- "{{ remote_tmp_dir }}"
exclude_path:
- "{{ remote_tmp_dir }}"
dest: "{{ remote_tmp_dir }}/archive_exclude_paths.{{ format }}"
format: "{{ format }}"
register: archive_excluded_paths
- name: Assert that excluded paths do not influence archive root - exclude path ({{ format }})
ansible.builtin.assert:
that:
- archive_excluded_paths.arcroot != remote_tmp_dir
- name: Remove archive - exclude path ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_exclude_paths.{{ format }}"
state: absent
@@ -0,0 +1,144 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Archive - file content idempotency ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_file_content_idempotency.{{ format }}"
format: "{{ format }}"
register: file_content_idempotency_before
- name: Modify file - file content idempotency ({{ format }})
ansible.builtin.lineinfile:
line: bar.txt
regexp: "^foo.txt$"
path: "{{ remote_tmp_dir }}/foo.txt"
- name: Archive second time - file content idempotency ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_file_content_idempotency.{{ format }}"
format: "{{ format }}"
register: file_content_idempotency_after
- name: Assert task status is changed - file content idempotency ({{ format }})
ansible.builtin.assert:
that:
- file_content_idempotency_after is changed
# Only ``zip`` archives are guaranteed to compare file content checksums rather than header checksums
when: "format == 'zip'"
- name: Remove archive - file content idempotency ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_file_content_idempotency.{{ format }}"
state: absent
- name: Modify file back - file content idempotency ({{ format }})
ansible.builtin.lineinfile:
line: foo.txt
regexp: "^bar.txt$"
path: "{{ remote_tmp_dir }}/foo.txt"
- name: Archive - file name idempotency ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_file_name_idempotency.{{ format }}"
format: "{{ format }}"
register: file_name_idempotency_before
- name: Rename file - file name idempotency ({{ format }})
ansible.builtin.command: "mv {{ remote_tmp_dir }}/foo.txt {{ remote_tmp_dir }}/fii.txt"
- name: Archive again - file name idempotency ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_file_name_idempotency.{{ format }}"
format: "{{ format }}"
register: file_name_idempotency_after
- name: Check task status - file name idempotency ({{ format }})
ansible.builtin.assert:
that:
- file_name_idempotency_after is changed
- name: Remove archive - file name idempotency ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_file_name_idempotency.{{ format }}"
state: absent
- name: Rename file back - file name idempotency ({{ format }})
ansible.builtin.command: "mv {{ remote_tmp_dir }}/fii.txt {{ remote_tmp_dir }}/foo.txt"
- name: Archive - single file content idempotency ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/foo.txt"
dest: "{{ remote_tmp_dir }}/archive_single_file_content_idempotency.{{ format }}"
format: "{{ format }}"
register: single_file_content_idempotency_before
- name: Modify file - single file content idempotency ({{ format }})
ansible.builtin.lineinfile:
line: bar.txt
regexp: "^foo.txt$"
path: "{{ remote_tmp_dir }}/foo.txt"
- name: Archive second time - single file content idempotency ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/foo.txt"
dest: "{{ remote_tmp_dir }}/archive_single_file_content_idempotency.{{ format }}"
format: "{{ format }}"
register: single_file_content_idempotency_after
- name: Assert task status is changed - single file content idempotency ({{ format }})
ansible.builtin.assert:
that:
- single_file_content_idempotency_after is changed
# ``tar`` archives are not guaranteed to identify changes to file content if the file meta properties are unchanged.
when: "format != 'tar'"
- name: Remove archive - single file content idempotency ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_single_file_content_idempotency.{{ format }}"
state: absent
- name: Modify file back - single file content idempotency ({{ format }})
ansible.builtin.lineinfile:
line: foo.txt
regexp: "^bar.txt$"
path: "{{ remote_tmp_dir }}/foo.txt"
- name: Archive - single file name idempotency ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/foo.txt"
dest: "{{ remote_tmp_dir }}/archive_single_file_name_idempotency.{{ format }}"
format: "{{ format }}"
register: single_file_name_idempotency_before
- name: Rename file - single file name idempotency ({{ format }})
ansible.builtin.command: "mv {{ remote_tmp_dir }}/foo.txt {{ remote_tmp_dir }}/fii.txt"
- name: Archive again - single file name idempotency ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/fii.txt"
dest: "{{ remote_tmp_dir }}/archive_single_file_name_idempotency.{{ format }}"
format: "{{ format }}"
register: single_file_name_idempotency_after
# The gz, bz2, and xz formats do not store the original file name
# so it is not possible to identify a change in this scenario.
- name: Check task status - single file name idempotency ({{ format }})
ansible.builtin.assert:
that:
- single_file_name_idempotency_after is changed
when: "format in ('tar', 'zip')"
- name: Remove archive - single file name idempotency ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_single_file_name_idempotency.{{ format }}"
state: absent
- name: Rename file back - single file name idempotency ({{ format }})
ansible.builtin.command: "mv {{ remote_tmp_dir }}/fii.txt {{ remote_tmp_dir }}/foo.txt"
@@ -0,0 +1,225 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Archive - remove source files ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/*.txt"
dest: "{{ remote_tmp_dir }}/archive_remove_source_files.{{ format }}"
format: "{{ format }}"
remove: true
register: archive_remove_source_files
- name: Verify archive exists - remove source files ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_files.{{ format }}"
state: file
- name: Verify all files were archived - remove source files ({{ format }})
ansible.builtin.assert:
that:
- archive_remove_source_files is changed
- "archive_remove_source_files.archived | length == 3"
- name: Remove Archive - remove source files ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_files.{{ format }}"
state: absent
- name: Remove source files in check mode ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/{{ item }}"
state: absent
check_mode: true
with_items:
- foo.txt
- bar.txt
- empty.txt
register: remove_files
- name: Assert that source files were removed - remove source files ({{ format }})
ansible.builtin.assert:
that:
- remove_files is not changed
- name: Copy source files - remove source directory ({{ format }})
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ remote_tmp_dir }}/{{ item }}"
with_items:
- foo.txt
- bar.txt
- empty.txt
- name: Create temporary directory - remove source directory ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/tmpdir"
state: directory
- name: Copy source files to temporary directory - remove source directory ({{ format }})
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ remote_tmp_dir }}/tmpdir/{{ item }}"
with_items:
- foo.txt
- bar.txt
- empty.txt
- name: Archive - remove source directory ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/tmpdir"
dest: "{{ remote_tmp_dir }}/archive_remove_source_directory.{{ format }}"
format: "{{ format }}"
remove: true
register: archive_remove_source_directory
- name: Verify archive exists - remove source directory ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_directory.{{ format }}"
state: file
- name: Verify archive contains all files - remove source directory ({{ format }})
ansible.builtin.assert:
that:
- archive_remove_source_directory is changed
- "archive_remove_source_directory.archived | length == 3"
- name: Remove archive - remove source directory ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_directory.{{ format }}"
state: absent
- name: Remove source source directory in check mode ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/tmpdir"
state: absent
check_mode: true
register: remove_dir
- name: Verify source directory was removed - remove source directory ({{ format }})
ansible.builtin.assert:
that:
- remove_dir is not changed
- name: Create temporary directory - remove source excluding path ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/tmpdir"
state: directory
- name: Copy source files to temporary directory - remove source excluding path ({{ format }})
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ remote_tmp_dir }}/tmpdir/{{ item }}"
with_items:
- foo.txt
- bar.txt
- empty.txt
- name: Archive - remove source excluding path ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/tmpdir/*"
dest: "{{ remote_tmp_dir }}/archive_remove_source_excluding_path.{{ format }}"
format: "{{ format }}"
remove: true
exclude_path: "{{ remote_tmp_dir }}/tmpdir/empty.txt"
register: archive_remove_source_excluding_path
- name: Verify archive exists - remove source excluding path ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_excluding_path.{{ format }}"
state: file
- name: Verify all files except excluded are archived - remove source excluding path ({{ format }})
ansible.builtin.assert:
that:
- archive_remove_source_excluding_path is changed
- "archive_remove_source_excluding_path.archived | length == 2"
- name: Remove archive - remove source excluding path ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_excluding_path.{{ format }}"
state: absent
- name: Verify that excluded file still exists - remove source excluding path ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/tmpdir/empty.txt"
state: file
- name: Copy source files to temporary directory - remove source excluding sub path ({{ format }})
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ remote_tmp_dir }}/tmpdir/{{ item }}"
with_items:
- foo.txt
- bar.txt
- empty.txt
- sub
- sub/subfile.txt
- name: Archive - remove source excluding sub path ({{ format }})
community.general.archive:
path:
- "{{ remote_tmp_dir }}/tmpdir/*.txt"
- "{{ remote_tmp_dir }}/tmpdir/sub/*"
dest: "{{ remote_tmp_dir }}/archive_remove_source_excluding_sub_path.{{ format }}"
format: "{{ format }}"
remove: true
exclude_path: "{{ remote_tmp_dir }}/tmpdir/sub/subfile.txt"
register: archive_remove_source_excluding_sub_path
- name: Verify archive exists - remove source excluding sub path ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_excluding_sub_path.{{ format }}"
state: file
- name: Remove archive - remove source excluding sub path ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_excluding_sub_path.{{ format }}"
state: absent
- name: Verify that sub path still exists - remove source excluding sub path ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/tmpdir/sub/subfile.txt"
state: file
- name: Copy source files to temporary directory - remove source with nested paths ({{ format }})
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ remote_tmp_dir }}/tmpdir/{{ item }}"
with_items:
- foo.txt
- bar.txt
- empty.txt
- sub
- sub/subfile.txt
- name: Archive - remove source with nested paths ({{ format }})
community.general.archive:
path: "{{ remote_tmp_dir }}/tmpdir/"
dest: "{{ remote_tmp_dir }}/archive_remove_source_nested_paths.{{ format }}"
format: "{{ format }}"
remove: true
register: archive_remove_nested_paths
- name: Verify archive exists - remove source with nested paths ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_nested_paths.{{ format }}"
state: file
- name: Verify source files were removed - remove source with nested paths ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/tmpdir"
state: absent
register: archive_remove_nested_paths_status
- name: Assert tasks status - remove source with nested paths ({{ format }})
ansible.builtin.assert:
that:
- archive_remove_nested_paths is success
- archive_remove_nested_paths_status is not changed
- name: Remove archive - remove source with nested paths ({{ format }})
ansible.builtin.file:
path: "{{ remote_tmp_dir }}/archive_remove_source_nested_paths.{{ format }}"
state: absent
@@ -0,0 +1,10 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
azp/posix/vm
destructive
needs/privileged
skip/freebsd
skip/macos
@@ -0,0 +1,20 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
btrfs_subvolume_single_configs:
- file: "/tmp/disks0.img"
loop: "/dev/loop95"
btrfs_subvolume_multiple_configs:
- file: "/tmp/diskm0.img"
loop: "/dev/loop97"
- file: "/tmp/diskm1.img"
loop: "/dev/loop98"
- file: "/tmp/diskm2.img"
loop: "/dev/loop99"
btrfs_subvolume_configs: "{{ btrfs_subvolume_single_configs + btrfs_subvolume_multiple_configs }}"
btrfs_subvolume_single_devices: "{{ btrfs_subvolume_single_configs | map(attribute='loop') }}"
btrfs_subvolume_single_label: "single"
btrfs_subvolume_multiple_devices: "{{ btrfs_subvolume_multiple_configs | map(attribute='loop') }}"
btrfs_subvolume_multiple_label: "multiple"
@@ -0,0 +1,29 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Install required packages
ansible.builtin.package:
name:
- btrfs-progs # btrfs userspace
- util-linux # losetup
ignore_errors: true
register: btrfs_installed
- name: Execute integration tests tests
block:
- ansible.builtin.include_tasks: 'setup.yml'
- name: "Execute test scenario for single device filesystem"
ansible.builtin.include_tasks: 'run_filesystem_tests.yml'
vars:
btrfs_subvolume_target_device: "{{ btrfs_subvolume_single_devices | first }}"
btrfs_subvolume_target_label: "{{ btrfs_subvolume_single_label }}"
- name: "Execute test scenario for multiple device configuration"
ansible.builtin.include_tasks: 'run_filesystem_tests.yml'
vars:
btrfs_subvolume_target_device: "{{ btrfs_subvolume_multiple_devices | first }}"
btrfs_subvolume_target_label: "{{ btrfs_subvolume_multiple_label }}"
when: btrfs_installed is success
@@ -0,0 +1,16 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- ansible.builtin.include_tasks: 'test_subvolume_simple.yml'
- ansible.builtin.include_tasks: 'test_subvolume_nested.yml'
- ansible.builtin.include_tasks: 'test_subvolume_in_directory.yml'
- ansible.builtin.include_tasks: 'test_subvolume_recursive.yml'
- ansible.builtin.include_tasks: 'test_subvolume_default.yml'
- ansible.builtin.include_tasks: 'test_snapshot_skip.yml'
- ansible.builtin.include_tasks: 'test_snapshot_clobber.yml'
- ansible.builtin.include_tasks: 'test_snapshot_error.yml'
- ansible.builtin.include_tasks: 'test_subvolume_whitespace.yml'
@@ -0,0 +1,32 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- ansible.builtin.include_tasks: 'test_filesystem_matching.yml'
- name: "Execute all test scenario for unmounted filesystem"
ansible.builtin.include_tasks: 'run_common_tests.yml'
- name: "Execute test scenarios where non-root subvolume is mounted"
block:
- name: Create subvolume '/nonroot'
community.general.btrfs_subvolume:
automount: true
name: "/nonroot"
filesystem_label: "{{ btrfs_subvolume_target_label }}"
state: "present"
register: nonroot
- name: "Mount subvolume '/nonroot'"
ansible.posix.mount:
src: "{{ nonroot.filesystem.devices | first }}"
path: /mnt
opts: "subvolid={{ nonroot.target_subvolume_id }}"
fstype: btrfs
state: mounted
- name: "Run tests for explicit, mounted single device configuration"
ansible.builtin.include_tasks: 'run_common_tests.yml'
- name: "Unmount subvolume /nonroot"
ansible.posix.mount:
path: /mnt
state: absent
@@ -0,0 +1,37 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Create file {{ item.file }} to back loop device {{ item.loop }}"
ansible.builtin.command:
cmd: "dd if=/dev/zero of={{ item.file }} bs=1M count=200" ## minimum count 109
creates: "{{ item.file }}"
with_items: "{{ btrfs_subvolume_configs }}"
- name: "Setup loop device {{ item.loop }}"
ansible.builtin.command:
cmd: "losetup {{ item.loop }} {{ item.file }}"
creates: "{{ item.loop }}"
with_items: "{{ btrfs_subvolume_configs }}"
- name: Create single device btrfs filesystem
ansible.builtin.command:
cmd: "mkfs.btrfs --label {{ btrfs_subvolume_single_label }} -f {{ btrfs_subvolume_single_devices | first }}"
changed_when: true
- name: Create multiple device btrfs filesystem
ansible.builtin.command:
cmd: "mkfs.btrfs --label {{ btrfs_subvolume_multiple_label }} -f -d raid0 {{ btrfs_subvolume_multiple_devices | join(' ') }}"
changed_when: true
# Typically created by udev, but apparently missing on Alpine
- name: Create btrfs control device node
ansible.builtin.command:
cmd: "mknod /dev/btrfs-control c 10 234"
creates: "/dev/btrfs-control"
- name: Force rescan to ensure all device are detected
ansible.builtin.command:
cmd: "btrfs device scan"
changed_when: true
@@ -0,0 +1,80 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: "Match targeted filesystem by label"
block:
- name: Match '{{ btrfs_subvolume_target_label }}' filesystem by label
community.general.btrfs_subvolume:
automount: true
name: "/match_label"
filesystem_label: "{{ btrfs_subvolume_target_label }}"
state: "present"
register: result
- name: Validate the '{{ btrfs_subvolume_target_label }}' filesystem was chosen
ansible.builtin.assert:
that:
- result.filesystem.label == btrfs_subvolume_target_label
- name: "Match targeted filesystem by uuid"
block:
- name: Match '{{ btrfs_subvolume_target_label }}' filesystem by uuid
community.general.btrfs_subvolume:
automount: true
name: "/match_uuid"
filesystem_uuid: "{{ result.filesystem.uuid }}"
state: "present"
register: result
- name: Validate the '{{ btrfs_subvolume_target_label }}' filesystem was chosen
ansible.builtin.assert:
that:
- result.filesystem.label == btrfs_subvolume_target_label
- name: "Match targeted filesystem by devices"
block:
- name: Match '{{ btrfs_subvolume_target_label }}' filesystem by device
community.general.btrfs_subvolume:
automount: true
name: "/match_device"
filesystem_device: "{{ result.filesystem.devices | first }}"
state: "present"
register: result
- name: Validate the '{{ btrfs_subvolume_target_label }}' filesystem was chosen
ansible.builtin.assert:
that:
- result.filesystem.label == btrfs_subvolume_target_label
- name: "Match only mounted filesystem"
block:
- name: "Mount filesystem '{{ btrfs_subvolume_target_label }}'"
ansible.posix.mount:
src: "{{ result.filesystem.devices | first }}"
path: /mnt
opts: "subvolid={{ 5 }}"
fstype: btrfs
state: mounted
- name: Print current status
community.general.btrfs_info:
- name: Match '{{ btrfs_subvolume_target_label }}' filesystem when only mount
community.general.btrfs_subvolume:
automount: true
name: "/match_only_mounted"
state: "present"
register: result
- name: "Unmount filesystem '{{ btrfs_subvolume_target_label }}'"
ansible.posix.mount:
path: /mnt
state: absent
- name: Validate the '{{ btrfs_subvolume_target_label }}' filesystem was chosen
ansible.builtin.assert:
that:
- result.filesystem.label == btrfs_subvolume_target_label
when: false # TODO don't attempt this if the host already has a pre-existing btrfs filesystem
@@ -0,0 +1,41 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create a snapshot, overwriting if one already exists at path
block:
- name: Create a snapshot named 'snapshot_clobber'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_clobber"
snapshot_source: "/"
snapshot_conflict: "clobber"
state: "present"
register: result
- name: Snapshot 'snapshot_clobber' created
ansible.builtin.assert:
that:
- result is changed
- name: Create a snapshot named 'snapshot_clobber' (no idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_clobber"
snapshot_source: "/"
snapshot_conflict: "clobber"
state: "present"
register: result
- name: Snapshot 'snapshot_clobber' created (no idempotency)
ansible.builtin.assert:
that:
- result is changed
- name: Cleanup created snapshot
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_clobber"
state: "absent"
@@ -0,0 +1,42 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create a snapshot, erroring if one already exists at path
block:
- name: Create a snapshot named 'snapshot_error'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_error"
snapshot_source: "/"
snapshot_conflict: "error"
state: "present"
register: result
- name: Snapshot 'snapshot_error' created
ansible.builtin.assert:
that:
- result is changed
- name: Create a snapshot named 'snapshot_error' (no idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_error"
snapshot_source: "/"
snapshot_conflict: "error"
state: "present"
register: result
ignore_errors: true
- name: Snapshot 'snapshot_error' created (no idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Cleanup created snapshot
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_error"
state: "absent"
@@ -0,0 +1,41 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create a snapshot if one does not already exist at path
block:
- name: Create a snapshot named 'snapshot_skip'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_skip"
snapshot_source: "/"
snapshot_conflict: "skip"
state: "present"
register: result
- name: Snapshot 'snapshot_skip' created
ansible.builtin.assert:
that:
- result is changed
- name: Create a snapshot named 'snapshot_skip' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_skip"
snapshot_source: "/"
snapshot_conflict: "skip"
state: "present"
register: result
- name: Snapshot 'snapshot_skip' created (idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Cleanup created snapshot
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/snapshot_skip"
state: "absent"
@@ -0,0 +1,99 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Change the default subvolume
block:
- name: Update filesystem default subvolume to '@'
community.general.btrfs_subvolume:
automount: true
default: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/@"
state: "present"
register: result
- name: Subvolume '@' set to default
ansible.builtin.assert:
that:
- result is changed
- name: Update filesystem default subvolume to '@' (idempotency)
community.general.btrfs_subvolume:
automount: true
default: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/@"
state: "present"
register: result
- name: Subvolume '@' set to default (idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Revert the default subvolume
block:
- name: Revert filesystem default subvolume to '/'
community.general.btrfs_subvolume:
automount: true
default: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/"
state: "present"
register: result
- name: Subvolume '/' set to default
ansible.builtin.assert:
that:
- result is changed
- name: Revert filesystem default subvolume to '/' (idempotency)
community.general.btrfs_subvolume:
automount: true
default: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/"
state: "present"
register: result
- name: Subvolume '/' set to default (idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Change the default subvolume again
block:
- name: Update filesystem default subvolume to '@'
community.general.btrfs_subvolume:
automount: true
default: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/@"
state: "present"
register: result
- name: Subvolume '@' set to default
ansible.builtin.assert:
that:
- result is changed
- name: Revert custom default subvolume to fs_tree root when deleted
block:
- name: Delete custom default subvolume '@'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/@"
state: "absent"
register: result
- name: Subvolume '@' deleted
ansible.builtin.assert:
that:
- result is changed
- name: Delete custom default subvolume '@' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/@"
state: "absent"
register: result
- name: Subvolume '@' deleted (idempotency)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,91 @@
---
# Copyright (c) 2026, Alexei Znamensky <russoz@gmail.com>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create directory 'plaindir' in the top level subvolume
block:
- name: Create temporary mountpoint for the top level subvolume
ansible.builtin.tempfile:
state: directory
register: toplevel_mountpoint
- name: Mount the top level subvolume
ansible.posix.mount:
src: "{{ btrfs_subvolume_target_device }}"
path: "{{ toplevel_mountpoint.path }}"
opts: "subvolid=5"
fstype: btrfs
state: mounted
- name: Create directory 'plaindir'
ansible.builtin.file:
path: "{{ toplevel_mountpoint.path }}/plaindir"
state: directory
always:
- name: Unmount the top level subvolume
ansible.posix.mount:
path: "{{ toplevel_mountpoint.path }}"
state: absent
- name: Create a subvolume named 'plaindir/parent'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/plaindir/parent"
state: "present"
- name: Create a nested subvolume inside a subvolume within a directory
block:
- name: Create a subvolume named 'nested' inside 'plaindir/parent'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/plaindir/parent/nested"
state: "present"
register: create_in_directory
- name: Subvolume 'plaindir/parent/nested' created
ansible.builtin.assert:
that:
- create_in_directory is changed
- name: Create a subvolume named 'nested' inside 'plaindir/parent' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/plaindir/parent/nested"
state: "present"
register: create_in_directory_again
- name: Subvolume 'plaindir/parent/nested' created (idempotency)
ansible.builtin.assert:
that:
- create_in_directory_again is not changed
- name: Remove a nested subvolume inside a subvolume within a directory
block:
- name: Remove a subvolume named 'nested' inside 'plaindir/parent'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/plaindir/parent/nested"
state: "absent"
register: remove_in_directory
- name: Subvolume 'plaindir/parent/nested' removed
ansible.builtin.assert:
that:
- remove_in_directory is changed
- name: Remove a subvolume named 'nested' inside 'plaindir/parent' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/plaindir/parent/nested"
state: "absent"
register: remove_in_directory_again
- name: Subvolume 'plaindir/parent/nested' removed (idempotency)
ansible.builtin.assert:
that:
- remove_in_directory_again is not changed
- name: Remove subvolume 'plaindir/parent'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/plaindir/parent"
state: "absent"
@@ -0,0 +1,61 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create parent subvolume 'container'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container"
state: "present"
- name: Create a nested subvolume
block:
- name: Create a subvolume named 'nested' inside 'container'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container/nested"
state: "present"
register: result
- name: Subvolume 'container/nested' created
ansible.builtin.assert:
that:
- result is changed
- name: Create a subvolume named 'nested' inside 'container' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container/nested"
state: "present"
register: result
- name: Subvolume 'container/nested' created (idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Remove a nested subvolume
block:
- name: Remove a subvolume named 'nested' inside 'container'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container/nested"
state: "absent"
register: result
- name: Subvolume 'container/nested' removed
ansible.builtin.assert:
that:
- result is changed
- name: Remove a subvolume named 'nested' inside 'container' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container/nested"
state: "absent"
register: result
- name: Subvolume 'container/nested' removed (idempotency)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,86 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Recursively create subvolumes
block:
- name: Create a subvolume named '/recursive/son/grandson'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/recursive/son/grandson"
recursive: true
state: "present"
register: result
- name: Subvolume named '/recursive/son/grandson' created
ansible.builtin.assert:
that:
- result is changed
- name: Create a subvolume named '/recursive/son/grandson' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/recursive/son/grandson"
recursive: true
state: "present"
register: result
- name: Subvolume named '/recursive/son/grandson' created (idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Create a subvolume named '/recursive/daughter/granddaughter'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/recursive/daughter/granddaughter"
recursive: true
state: "present"
register: result
- name: Subvolume named '/recursive/son/grandson' created
ansible.builtin.assert:
that:
- result is changed
- name: Create a subvolume named '/recursive/daughter/granddaughter' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/recursive/daughter/granddaughter"
recursive: true
state: "present"
register: result
- name: Subvolume named '/recursive/son/grandson' created (idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Recursively remove subvolumes
block:
- name: Remove subvolume '/recursive' and all descendents
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/recursive"
recursive: true
state: "absent"
register: result
- name: Subvolume '/recursive' removed
ansible.builtin.assert:
that:
- result is changed
- name: Remove subvolume '/recursive' and all descendents (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/recursive"
recursive: true
state: "absent"
register: result
- name: Subvolume '/recursive' removed (idempotency)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,54 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create a simple subvolume
block:
- name: Create a subvolume named 'simple'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/simple"
state: "present"
register: result
- name: Subvolume named 'simple' created
ansible.builtin.assert:
that:
- result is changed
- name: Create a subvolume named 'simple' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/simple"
state: "present"
register: result
- name: Subvolume named 'simple' created (idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Remove a simple subvolume
block:
- name: Remove a subvolume named 'simple'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/simple"
state: "absent"
register: result
- name: Subvolume named 'simple' removed
ansible.builtin.assert:
that:
- result is changed
- name: Remove a subvolume named 'simple' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/simple"
state: "absent"
register: result
- name: Subvolume named 'simple' removed (idempotency)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,62 @@
---
# Copyright (c) 2022, Gregory Furlong <gnfzdz@fzdz.io>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create a subvolume named 'container'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container"
state: "present"
- name: Create a subvolume with whitespace in the name
block:
- name: Create a subvolume named 'container/my data'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container/my data"
state: "present"
register: result
- name: Subvolume named 'container/my data' created
ansible.builtin.assert:
that:
- result is changed
- name: Create a subvolume named 'container/my data' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container/my data"
state: "present"
register: result
- name: Subvolume named 'container/my data' created (idempotency)
ansible.builtin.assert:
that:
- result is not changed
- name: Remove a subvolume with whitespace in the name
block:
- name: Remove a subvolume named 'container/my data'
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container/my data"
state: "absent"
register: result
- name: Subvolume named 'container/my data' removed
ansible.builtin.assert:
that:
- result is changed
- name: Remove a subvolume named 'container/my data' (idempotency)
community.general.btrfs_subvolume:
automount: true
filesystem_label: "{{ btrfs_subvolume_target_label }}"
name: "/container/my data"
state: "absent"
register: result
- name: Subvolume named 'container/my data' removed (idempotency)
ansible.builtin.assert:
that:
- result is not changed
@@ -0,0 +1,56 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
from __future__ import annotations
def callback_results_extractor(outputs_results):
results = []
for result in outputs_results:
differences = []
expected_output = result["test"]["expected_output"]
stdout_lines = result["stdout_lines"]
for i in range(max(len(expected_output), len(stdout_lines))):
test_line = stdout_lines[i] if i < len(stdout_lines) else None
expected_lines = expected_output[i] if i < len(expected_output) else None
if not isinstance(expected_lines, str) and expected_lines is not None:
if test_line not in expected_lines:
differences.append(
{
"line": {
"expected_one_of": expected_lines,
"got": test_line,
}
}
)
else:
if test_line != expected_lines:
differences.append(
{
"line": {
"expected": expected_lines,
"got": test_line,
}
}
)
results.append(
{
"name": result["test"]["name"],
"output": {
"differences": differences,
"expected": expected_output,
"got": stdout_lines,
},
}
)
return results
class FilterModule:
"""Jinja2 compat filters"""
def filters(self):
return {
"callback_results_extractor": callback_results_extractor,
}
@@ -0,0 +1,9 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
all:
hosts:
testhost:
ansible_connection: local
@@ -0,0 +1,67 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- name: Create temporary playbook files
ansible.builtin.tempfile:
state: file
suffix: temp
loop: "{{ tests }}"
loop_control:
loop_var: test
label: "{{ test.name }}"
register: temporary_playbook_files
- name: Set temporary playbook file content
ansible.builtin.copy:
content: "{{ test.playbook }}"
dest: "{{ temporary_playbook_files.results[test_idx].path }}"
loop: "{{ tests }}"
loop_control:
loop_var: test
index_var: test_idx
label: "{{ test.name }}"
- name: Collect outputs
ansible.builtin.command: "ansible-playbook -i {{ inventory }} {{ playbook }} {{ test.extra_cli_arguments | default('') }}"
environment: "{{ test.environment }}"
loop: "{{ tests }}"
loop_control:
loop_var: test
label: "{{ test.name }}"
register: outputs
changed_when: false
vars:
inventory: "{{ role_path }}/inventory.yml"
playbook: "
{%- for result in temporary_playbook_files.results -%}
{%- if result.test.name == test.name -%}
{{- result.path -}}
{%- endif -%}
{%- endfor -%}"
- name: Assert test output equals expected output
ansible.builtin.assert:
that: result.output.differences | length == 0
loop: "{{ outputs.results | callback_results_extractor }}"
loop_control:
loop_var: result
label: "{{ result.name }}"
register: assertions
always:
- name: Remove temporary playbooks
ansible.builtin.file:
path: "{{ temporary_file.path }}"
state: absent
loop: "{{ temporary_playbook_files.results }}"
loop_control:
loop_var: temporary_file
label: "{{ temporary_file.test.name }}: {{ temporary_file.path }}"
@@ -0,0 +1,6 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
needs/target/callback
@@ -0,0 +1,102 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Run tests
ansible.builtin.include_role:
name: callback
vars:
tests:
- name: Task and host counters shown in N/M format
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.counter_enabled
playbook: |
- hosts: testhost
gather_facts: false
tasks:
- name: First task
ansible.builtin.set_fact:
counter_test: first
- name: Second task
ansible.builtin.set_fact:
counter_test: second
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK 1/2 [First task] **********************************************************"
- "ok: 1/1 [testhost]"
- ""
- "TASK 2/2 [Second task] *********************************************************"
- "ok: 1/1 [testhost]"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=2 changed=0 unreachable=0 failed=0 rescued=0 ignored=0 "
- name: Loop task items are displayed (regression for issue 8187)
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.counter_enabled
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Loop task
ansible.builtin.set_fact:
dummy_fact: "{{ item }}"
loop:
- item_a
- item_b
- item_c
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK 1/1 [Loop task] ***********************************************************"
- "ok: [testhost] => (item=item_a)"
- "ok: [testhost] => (item=item_b)"
- "ok: [testhost] => (item=item_c)"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 rescued=0 ignored=0 "
- name: Delegated loop task items show delegation target (regression for issue 8187)
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.counter_enabled
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Delegated loop task
ansible.builtin.set_fact:
dummy_fact: "{{ item }}"
loop:
- item_a
- item_b
- item_c
delegate_to: localhost
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK 1/1 [Delegated loop task] *************************************************"
- - "ok: [testhost -> localhost] => (item=item_a)"
- "ok: [testhost -> localhost(127.0.0.1)] => (item=item_a)"
- - "ok: [testhost -> localhost] => (item=item_b)"
- "ok: [testhost -> localhost(127.0.0.1)] => (item=item_b)"
- - "ok: [testhost -> localhost] => (item=item_c)"
- "ok: [testhost -> localhost(127.0.0.1)] => (item=item_c)"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 rescued=0 ignored=0 "
@@ -0,0 +1,6 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
needs/target/callback
@@ -0,0 +1,64 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- block:
- name: Create temporary file
ansible.builtin.tempfile:
register: tempfile
- name: Run tests
ansible.builtin.include_role:
name: callback
vars:
tests:
- name: Basic file diff
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_DIFF_ALWAYS: 'true'
ANSIBLE_PYTHON_INTERPRETER: "{{ ansible_python_interpreter }}"
ANSIBLE_STDOUT_CALLBACK: community.general.default_without_diff
playbook: |
- hosts: testhost
gather_facts: true
tasks:
- name: Create file
ansible.builtin.copy:
dest: "{{ tempfile.path }}"
content: |
Foo bar
- name: Modify file
ansible.builtin.copy:
dest: "{{ tempfile.path }}"
content: |
Foo bar
Bar baz bam!
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Gathering Facts] *********************************************************"
- "ok: [testhost]"
- ""
- "TASK [Create file] *************************************************************"
- "changed: [testhost]"
- ""
- "TASK [Modify file] *************************************************************"
- "changed: [testhost]"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=3 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
always:
- name: Clean up temp file
ansible.builtin.file:
path: "{{ tempfile.path }}"
state: absent
@@ -0,0 +1,6 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3
needs/target/callback
@@ -0,0 +1,505 @@
---
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Run tests
ansible.builtin.include_role:
name: callback
vars:
tests:
- name: Not using diy callback options
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "ok: [testhost] => {"
- " \"msg\": \"sample debug msg\""
- "}"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set playbook_on_start_msg callback using environment variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
ANSIBLE_CALLBACK_DIY_PLAYBOOK_ON_START_MSG: "Sample output Sample playbook message"
playbook: |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
expected_output:
- "Sample output Sample playbook message"
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "ok: [testhost] => {"
- " \"msg\": \"sample debug msg\""
- "}"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set playbook_on_play_start_msg callback using play variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- name: Sample play name
hosts: testhost
gather_facts: false
vars:
ansible_callback_diy_playbook_on_play_start_msg: Sample output {{ ansible_callback_diy.play.name }}
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
expected_output:
- "Sample output Sample play name"
- ""
- "TASK [Sample task name] ********************************************************"
- "ok: [testhost] => {"
- " \"msg\": \"sample debug msg\""
- "}"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set playbook_on_task_start_msg callback using play variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
vars:
ansible_callback_diy_playbook_on_task_start_msg: Sample output {{ ansible_callback_diy.task.name }}
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- "Sample output Sample task name"
- "ok: [testhost] => {"
- " \"msg\": \"sample debug msg\""
- "}"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set playbook_on_task_start_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
vars:
ansible_callback_diy_playbook_on_task_start_msg: Sample output {{ ansible_callback_diy.task.name }}
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- "Sample output Sample task name"
- "ok: [testhost] => {"
- " \"msg\": \"sample debug msg\""
- "}"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set runner_on_ok_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
vars:
ansible_callback_diy_runner_on_ok_msg: Sample output {{ ansible_callback_diy.result.output.msg }}
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "Sample output sample debug msg"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set runner_on_failed_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
failed_when: true
ignore_errors: true
vars:
ansible_callback_diy_runner_on_failed_msg: Sample output Sample failure message
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "Sample output Sample failure message"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1 "
- name: Set runner_on_skipped_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
when: false
vars:
ansible_callback_diy_runner_on_skipped_msg: Sample output Skipped {{ ansible_callback_diy.task.name }}
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "Sample output Skipped Sample task name"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=0 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 "
- name: Set runner_item_on_ok_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg {{ item }}
loop:
- sample item 1
- sample item 2
- sample item 3
vars:
ansible_callback_diy_runner_item_on_ok_msg: Sample output Looping {{ ansible_callback_diy.result.output.msg }}
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "Sample output Looping sample debug msg sample item 1"
- "Sample output Looping sample debug msg sample item 2"
- "Sample output Looping sample debug msg sample item 3"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set runner_item_on_failed_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg {{ item }}
loop:
- sample item 1
- sample item 2
- sample item 3
failed_when: item == 'sample item 2'
ignore_errors: true
vars:
ansible_callback_diy_runner_item_on_failed_msg: Sample output Looping sample failure message
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "ok: [testhost] => (item=sample item 1) => {"
- " \"msg\": \"sample debug msg sample item 1\""
- "}"
- "Sample output Looping sample failure message"
- "ok: [testhost] => (item=sample item 3) => {"
- " \"msg\": \"sample debug msg sample item 3\""
- "}"
- # Apparently a bug was fixed in Ansible, as before it ran through with "All items completed"
- "fatal: [testhost]: FAILED! => {\"msg\": \"All items completed\"}"
- "fatal: [testhost]: FAILED! => {\"msg\": \"One or more items failed\"}"
- "...ignoring"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=1 "
- name: Set runner_item_on_skipped_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg {{ item }}
loop:
- sample item 1
- sample item 2
- sample item 3
when: item != 'sample item 2'
vars:
ansible_callback_diy_runner_item_on_skipped_msg: Sample output Looping Skipped {{ ansible_callback_diy.result.output.item }}
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "ok: [testhost] => (item=sample item 1) => {"
- " \"msg\": \"sample debug msg sample item 1\""
- "}"
- "Sample output Looping Skipped sample item 2"
- "ok: [testhost] => (item=sample item 3) => {"
- " \"msg\": \"sample debug msg sample item 3\""
- "}"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set playbook_on_stats_msg callback using play variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
vars:
ansible_callback_diy_playbook_on_stats_msg: |+2
Sample output stats
===============================
{% for key in ansible_callback_diy.stats | sort %}
{% set color_one = "" %}
{% set color_two = "" %}
{% if ansible_callback_diy.stats[key] %}
{% if key == 'ok' %}
{% set prefix = ' ' %}
{% set suffix = ' ' %}
{% elif key == 'changed' %}
{% set prefix = ' ' %}
{% set suffix = ' ' %}
{% elif key == 'processed' %}
{% set prefix = ' ' %}
{% set suffix = ' ' %}
{% elif key == 'skipped' %}
{% set prefix = ' ' %}
{% set suffix = ' ' %}
{% else %}
{% set prefix = "" %}
{% set suffix = "" %}
{% endif %}
{{ color_one }}{{ "%s%s%s" | format(prefix,key,suffix) }}{{ color_two }}: {{ ansible_callback_diy.stats[key] | to_nice_yaml }}
{% endif %}
{% endfor %}
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "ok: [testhost] => {"
- " \"msg\": \"sample debug msg\""
- "}"
- " Sample output stats"
- "==============================="
- " ok : testhost: 1"
- ""
- " processed : testhost: 1"
- name: Suppress output on playbook_on_task_start_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
vars:
ansible_callback_diy_playbook_on_task_start_msg: ''
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- "ok: [testhost] => {"
- " \"msg\": \"sample debug msg\""
- "}"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Suppress output on runner_on_ok_msg callback using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
vars:
ansible_callback_diy_runner_on_ok_msg: ''
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set runner_on_ok_msg_color using task variable
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
vars:
ansible_callback_diy_runner_on_ok_msg: Sample output {{ ansible_callback_diy.result.output.msg }}
ansible_callback_diy_runner_on_ok_msg_color: blue
expected_output:
- ""
- "PLAY [testhost] ****************************************************************"
- ""
- "TASK [Sample task name] ********************************************************"
- "Sample output sample debug msg"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 "
- name: Set on_any_msg
environment:
ANSIBLE_NOCOLOR: 'true'
ANSIBLE_FORCE_COLOR: 'false'
ANSIBLE_STDOUT_CALLBACK: community.general.diy
ANSIBLE_CALLBACK_DIY_ON_ANY_MSG: foo
playbook: !unsafe |
- hosts: testhost
gather_facts: false
tasks:
- name: A loop
ansible.builtin.debug:
msg: "{{ item }}"
loop:
- 1
- 2
- name: Sample task name
ansible.builtin.debug:
msg: sample debug msg
- name: Skipped task
ansible.builtin.command: ls /
when: false
expected_output:
- "foo"
- ""
- "PLAY [testhost] ****************************************************************"
- "foo"
- ""
- "TASK [A loop] ******************************************************************"
- "foo"
- "foo"
- "ok: [testhost] => (item=1) => {"
- " \"msg\": 1"
- "}"
- "foo"
- "ok: [testhost] => (item=2) => {"
- " \"msg\": 2"
- "}"
- "foo"
- "foo"
- ""
- "TASK [Sample task name] ********************************************************"
- "foo"
- "foo"
- "ok: [testhost] => {"
- " \"msg\": \"sample debug msg\""
- "}"
- "foo"
- ""
- "TASK [Skipped task] ************************************************************"
- "foo"
- "foo"
- "skipping: [testhost]"
- "foo"
- ""
- "PLAY RECAP *********************************************************************"
- "testhost : ok=2 changed=0 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0 "
- ""
- "foo"
@@ -0,0 +1,5 @@
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
azp/posix/3

Some files were not shown because too many files have changed in this diff Show More