From f9a5afccfe79b3524cb6be8bb5736196d9bb79bc Mon Sep 17 00:00:00 2001 From: Francisco-Xiq Date: Sun, 17 May 2026 18:31:34 -0300 Subject: [PATCH 01/11] feat: new module apache2_site - enable/disable Apache2 Sites on Debian Systems --- changelogs/fragments/9209-apache2-site.yml | 2 + plugins/modules/apache2_site.py | 112 ++++++++++++++++++ .../integration/targets/apache2_site/aliases | 6 + .../targets/apache2_site/meta/main.yml | 7 ++ .../targets/apache2_site/tasks/actualtest.yml | 103 ++++++++++++++++ .../targets/apache2_site/tasks/main.yml | 40 +++++++ 6 files changed, 270 insertions(+) create mode 100644 changelogs/fragments/9209-apache2-site.yml create mode 100644 plugins/modules/apache2_site.py create mode 100644 tests/integration/targets/apache2_site/aliases create mode 100644 tests/integration/targets/apache2_site/meta/main.yml create mode 100644 tests/integration/targets/apache2_site/tasks/actualtest.yml create mode 100644 tests/integration/targets/apache2_site/tasks/main.yml diff --git a/changelogs/fragments/9209-apache2-site.yml b/changelogs/fragments/9209-apache2-site.yml new file mode 100644 index 0000000000..5efcdb2fde --- /dev/null +++ b/changelogs/fragments/9209-apache2-site.yml @@ -0,0 +1,2 @@ +minor_changes: + - apache2_site - new module to enable/disable Apache2 sites using ``a2ensite`` and ``a2dissite`` (https://github.com/ansible-collections/community.general/issues/9209). diff --git a/plugins/modules/apache2_site.py b/plugins/modules/apache2_site.py new file mode 100644 index 0000000000..d141ad16ba --- /dev/null +++ b/plugins/modules/apache2_site.py @@ -0,0 +1,112 @@ +#!/usr/bin/python + +# Copyright (c) 2025, Francisco Pereira (@Francisco-Xiq) +# 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 + +DOCUMENTATION = r""" +module: apache2_site +author: + - Francisco Pereira (@Francisco-Xiq) +short_description: Enables/disables a site of the Apache2 webserver +description: + - Enables or disables a specified site of the Apache2 webserver. + - Uses C(a2ensite) and C(a2dissite) under the hood. +notes: + - This module is only available on Debian/Ubuntu-based systems, + as it depends on C(a2ensite) and C(a2dissite). +extends_documentation_fragment: + - community.general._attributes +attributes: + check_mode: + support: full + diff_mode: + support: none +options: + name: + type: str + description: + - Name of the site to enable/disable as given to C(a2ensite)/C(a2dissite). + - The name should not include the C(.conf) extension. + required: true + state: + type: str + description: + - Desired state of the site. + choices: [present, absent] + required: true +""" + +EXAMPLES = r""" +- name: Enable my_cool_site + community.general.apache2_site: + state: present + name: my_cool_site + +- name: Disable old site + community.general.apache2_site: + state: absent + name: very_old_site +""" + +RETURN = r""" +name: + description: Name of the site. + returned: success + type: str + sample: my_cool_site +""" + +import os +from ansible.module_utils.basic import AnsibleModule + + +def site_is_enabled(name): + return os.path.islink(f"/etc/apache2/sites-enabled/{name}.conf") + + +def main(): + module = AnsibleModule( + argument_spec=dict( + name=dict(type="str", required=True), + state=dict(type="str", required=True, choices=["present", "absent"]), + ), + supports_check_mode=True, + ) + + name = module.params["name"] + state = module.params["state"] + want_enabled = state == "present" + is_enabled = site_is_enabled(name) + + changed = False + + if want_enabled and not is_enabled: + changed = True + if not module.check_mode: + a2ensite = module.get_bin_path("a2ensite", required=True) + rc, stdout, stderr = module.run_command([a2ensite, name]) + if rc != 0: + module.fail_json( + msg=f"Failed to enable site {name}: {stderr}", + rc=rc, stdout=stdout, stderr=stderr + ) + + elif not want_enabled and is_enabled: + changed = True + if not module.check_mode: + a2dissite = module.get_bin_path("a2dissite", required=True) + rc, stdout, stderr = module.run_command([a2dissite, name]) + if rc != 0: + module.fail_json( + msg=f"Failed to disable site {name}: {stderr}", + rc=rc, stdout=stdout, stderr=stderr + ) + + module.exit_json(changed=changed, name=name) + + +if __name__ == "__main__": + main() diff --git a/tests/integration/targets/apache2_site/aliases b/tests/integration/targets/apache2_site/aliases new file mode 100644 index 0000000000..1eac407375 --- /dev/null +++ b/tests/integration/targets/apache2_site/aliases @@ -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 diff --git a/tests/integration/targets/apache2_site/meta/main.yml b/tests/integration/targets/apache2_site/meta/main.yml new file mode 100644 index 0000000000..f32339acf0 --- /dev/null +++ b/tests/integration/targets/apache2_site/meta/main.yml @@ -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 diff --git a/tests/integration/targets/apache2_site/tasks/actualtest.yml b/tests/integration/targets/apache2_site/tasks/actualtest.yml new file mode 100644 index 0000000000..4e0adfdd21 --- /dev/null +++ b/tests/integration/targets/apache2_site/tasks/actualtest.yml @@ -0,0 +1,103 @@ +--- +# 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 + +# Setup: create a minimal site config for testing +- name: create test site config + ansible.builtin.copy: + dest: /etc/apache2/sites-available/ansible_test_site.conf + content: | + + ServerName ansible-test.local + DocumentRoot /var/www/html + + +# ------------------------------------------------------------------ +# Test: enable a site +# ------------------------------------------------------------------ +- name: enable test site + community.general.apache2_site: + name: ansible_test_site + state: present + register: enable_first + +- name: ensure changed on first enable + ansible.builtin.assert: + that: + - enable_first is changed + +# ------------------------------------------------------------------ +# Test: idempotency on enable +# ------------------------------------------------------------------ +- name: enable test site again (idempotency check) + community.general.apache2_site: + name: ansible_test_site + state: present + register: enable_second + +- name: ensure idempotency on enable + ansible.builtin.assert: + that: + - enable_second is not changed + +# ------------------------------------------------------------------ +# Test: disable a site +# ------------------------------------------------------------------ +- name: disable test site + community.general.apache2_site: + name: ansible_test_site + state: absent + register: disable_first + +- name: ensure changed on first disable + ansible.builtin.assert: + that: + - disable_first is changed + +# ------------------------------------------------------------------ +# Test: idempotency on disable +# ------------------------------------------------------------------ +- name: disable test site again (idempotency check) + community.general.apache2_site: + name: ansible_test_site + state: absent + register: disable_second + +- name: ensure idempotency on disable + ansible.builtin.assert: + that: + - disable_second is not changed + +# ------------------------------------------------------------------ +# Test: check_mode does not make changes +# ------------------------------------------------------------------ +- name: enable test site in check_mode + community.general.apache2_site: + name: ansible_test_site + state: present + check_mode: true + register: check_mode_result + +- name: ensure check_mode reports changed + ansible.builtin.assert: + that: + - check_mode_result is changed + +- name: ensure check_mode did not actually enable the site + ansible.builtin.stat: + path: /etc/apache2/sites-enabled/ansible_test_site.conf + register: site_stat + +- name: assert symlink was not created in check_mode + ansible.builtin.assert: + that: + - not site_stat.stat.exists + +# ------------------------------------------------------------------ +# Cleanup: remove test site config +# ------------------------------------------------------------------ +- name: remove test site config + ansible.builtin.file: + path: /etc/apache2/sites-available/ansible_test_site.conf + state: absent diff --git a/tests/integration/targets/apache2_site/tasks/main.yml b/tests/integration/targets/apache2_site/tasks/main.yml new file mode 100644 index 0000000000..a51e058259 --- /dev/null +++ b/tests/integration/targets/apache2_site/tasks/main.yml @@ -0,0 +1,40 @@ +--- +#################################################################### +# 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_site + block: + - name: get list of enabled sites before tests + ansible.builtin.command: ls /etc/apache2/sites-enabled/ + register: sites_before + changed_when: false + + - name: include actual tests + include_tasks: actualtest.yml + + always: + - name: get list of enabled sites after tests + ansible.builtin.command: ls /etc/apache2/sites-enabled/ + register: sites_after + changed_when: false + + - name: sites before tests + ansible.builtin.debug: + var: sites_before.stdout_lines + + - name: sites after tests + ansible.builtin.debug: + var: sites_after.stdout_lines + + - name: ensure that all test sites are disabled again + ansible.builtin.assert: + that: sites_before.stdout == sites_after.stdout + + when: ansible_facts.os_family == 'Debian' + # a2ensite/a2dissite are Debian/Ubuntu specific tools From 912b37e062ec03fb3d8f9b203deefce6c94eb5dc Mon Sep 17 00:00:00 2001 From: Francisco-Xiq Date: Sun, 17 May 2026 18:41:11 -0300 Subject: [PATCH 02/11] tests/integration/targets/apache2_site/tasks/actualtest.yml: remove unnecessary comments --- .../targets/apache2_site/tasks/actualtest.yml | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tests/integration/targets/apache2_site/tasks/actualtest.yml b/tests/integration/targets/apache2_site/tasks/actualtest.yml index 4e0adfdd21..3a12bae737 100644 --- a/tests/integration/targets/apache2_site/tasks/actualtest.yml +++ b/tests/integration/targets/apache2_site/tasks/actualtest.yml @@ -3,7 +3,6 @@ # 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 -# Setup: create a minimal site config for testing - name: create test site config ansible.builtin.copy: dest: /etc/apache2/sites-available/ansible_test_site.conf @@ -13,9 +12,6 @@ DocumentRoot /var/www/html -# ------------------------------------------------------------------ -# Test: enable a site -# ------------------------------------------------------------------ - name: enable test site community.general.apache2_site: name: ansible_test_site @@ -27,9 +23,6 @@ that: - enable_first is changed -# ------------------------------------------------------------------ -# Test: idempotency on enable -# ------------------------------------------------------------------ - name: enable test site again (idempotency check) community.general.apache2_site: name: ansible_test_site @@ -41,9 +34,6 @@ that: - enable_second is not changed -# ------------------------------------------------------------------ -# Test: disable a site -# ------------------------------------------------------------------ - name: disable test site community.general.apache2_site: name: ansible_test_site @@ -55,9 +45,6 @@ that: - disable_first is changed -# ------------------------------------------------------------------ -# Test: idempotency on disable -# ------------------------------------------------------------------ - name: disable test site again (idempotency check) community.general.apache2_site: name: ansible_test_site @@ -69,9 +56,6 @@ that: - disable_second is not changed -# ------------------------------------------------------------------ -# Test: check_mode does not make changes -# ------------------------------------------------------------------ - name: enable test site in check_mode community.general.apache2_site: name: ansible_test_site @@ -94,9 +78,6 @@ that: - not site_stat.stat.exists -# ------------------------------------------------------------------ -# Cleanup: remove test site config -# ------------------------------------------------------------------ - name: remove test site config ansible.builtin.file: path: /etc/apache2/sites-available/ansible_test_site.conf From 1a83290778093b08744af6058cfdec822c91d469 Mon Sep 17 00:00:00 2001 From: Francisco-Xiq Date: Sun, 17 May 2026 19:42:31 -0300 Subject: [PATCH 03/11] remove: unncessary changelog file for new module --- changelogs/fragments/9209-apache2-site.yml | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 changelogs/fragments/9209-apache2-site.yml diff --git a/changelogs/fragments/9209-apache2-site.yml b/changelogs/fragments/9209-apache2-site.yml deleted file mode 100644 index 5efcdb2fde..0000000000 --- a/changelogs/fragments/9209-apache2-site.yml +++ /dev/null @@ -1,2 +0,0 @@ -minor_changes: - - apache2_site - new module to enable/disable Apache2 sites using ``a2ensite`` and ``a2dissite`` (https://github.com/ansible-collections/community.general/issues/9209). From 7156a4b8f763095a8c5a9ecab39ca64f92794f9c Mon Sep 17 00:00:00 2001 From: Francisco-Xiq Date: Sun, 17 May 2026 19:55:59 -0300 Subject: [PATCH 04/11] feat: .github/BOTMETA.yml new entry --- .github/BOTMETA.yml | 2 ++ plugins/modules/apache2_site.py | 11 +++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/BOTMETA.yml b/.github/BOTMETA.yml index 963ef722b2..a9be12bbcb 100644 --- a/.github/BOTMETA.yml +++ b/.github/BOTMETA.yml @@ -478,6 +478,8 @@ files: $modules/apache2_module.py: ignore: robinro maintainers: berendt n0trax + $modules/apache2_site.py: + maintainers: Francisco-Xiq $modules/apk.py: ignore: kbrebanov labels: apk diff --git a/plugins/modules/apache2_site.py b/plugins/modules/apache2_site.py index d141ad16ba..c53b7ca8f2 100644 --- a/plugins/modules/apache2_site.py +++ b/plugins/modules/apache2_site.py @@ -60,6 +60,7 @@ name: """ import os + from ansible.module_utils.basic import AnsibleModule @@ -89,10 +90,7 @@ def main(): a2ensite = module.get_bin_path("a2ensite", required=True) rc, stdout, stderr = module.run_command([a2ensite, name]) if rc != 0: - module.fail_json( - msg=f"Failed to enable site {name}: {stderr}", - rc=rc, stdout=stdout, stderr=stderr - ) + module.fail_json(msg=f"Failed to enable site {name}: {stderr}", rc=rc, stdout=stdout, stderr=stderr) elif not want_enabled and is_enabled: changed = True @@ -100,10 +98,7 @@ def main(): a2dissite = module.get_bin_path("a2dissite", required=True) rc, stdout, stderr = module.run_command([a2dissite, name]) if rc != 0: - module.fail_json( - msg=f"Failed to disable site {name}: {stderr}", - rc=rc, stdout=stdout, stderr=stderr - ) + module.fail_json(msg=f"Failed to disable site {name}: {stderr}", rc=rc, stdout=stdout, stderr=stderr) module.exit_json(changed=changed, name=name) From deccd7a02ea56f648bf5228bb30bf3d82bcf4340 Mon Sep 17 00:00:00 2001 From: Francisco-Xiq Date: Sun, 17 May 2026 20:27:34 -0300 Subject: [PATCH 05/11] apache2_site: apply review suggestions --- plugins/modules/apache2_site.py | 10 +++------- tests/integration/targets/apache2_site/aliases | 5 +++++ tests/integration/targets/apache2_site/tasks/main.yml | 8 ++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/plugins/modules/apache2_site.py b/plugins/modules/apache2_site.py index c53b7ca8f2..ba436c6590 100644 --- a/plugins/modules/apache2_site.py +++ b/plugins/modules/apache2_site.py @@ -1,6 +1,6 @@ #!/usr/bin/python -# Copyright (c) 2025, Francisco Pereira (@Francisco-Xiq) +# Copyright (c) 2026, Francisco Pereira (@Francisco-Xiq) # 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 @@ -88,17 +88,13 @@ def main(): changed = True if not module.check_mode: a2ensite = module.get_bin_path("a2ensite", required=True) - rc, stdout, stderr = module.run_command([a2ensite, name]) - if rc != 0: - module.fail_json(msg=f"Failed to enable site {name}: {stderr}", rc=rc, stdout=stdout, stderr=stderr) + module.run_command([a2ensite, name], check_rc=True) elif not want_enabled and is_enabled: changed = True if not module.check_mode: a2dissite = module.get_bin_path("a2dissite", required=True) - rc, stdout, stderr = module.run_command([a2dissite, name]) - if rc != 0: - module.fail_json(msg=f"Failed to disable site {name}: {stderr}", rc=rc, stdout=stdout, stderr=stderr) + module.run_command([a2dissite, name], check_rc=True) module.exit_json(changed=changed, name=name) diff --git a/tests/integration/targets/apache2_site/aliases b/tests/integration/targets/apache2_site/aliases index 1eac407375..fa3119327f 100644 --- a/tests/integration/targets/apache2_site/aliases +++ b/tests/integration/targets/apache2_site/aliases @@ -4,3 +4,8 @@ azp/posix/3 destructive + +skip/rhel +skip/freebsd +skip/macos +skip/alpine diff --git a/tests/integration/targets/apache2_site/tasks/main.yml b/tests/integration/targets/apache2_site/tasks/main.yml index a51e058259..3992755dee 100644 --- a/tests/integration/targets/apache2_site/tasks/main.yml +++ b/tests/integration/targets/apache2_site/tasks/main.yml @@ -9,6 +9,9 @@ # SPDX-License-Identifier: GPL-3.0-or-later - name: test apache2_site + + when: ansible_facts.os_family == 'Debian' + block: - name: get list of enabled sites before tests ansible.builtin.command: ls /etc/apache2/sites-enabled/ @@ -16,9 +19,8 @@ changed_when: false - name: include actual tests - include_tasks: actualtest.yml + ansible.builtin.include_tasks: actualtest.yml - always: - name: get list of enabled sites after tests ansible.builtin.command: ls /etc/apache2/sites-enabled/ register: sites_after @@ -36,5 +38,3 @@ ansible.builtin.assert: that: sites_before.stdout == sites_after.stdout - when: ansible_facts.os_family == 'Debian' - # a2ensite/a2dissite are Debian/Ubuntu specific tools From 64548cbd9982af8a5b461a8855d28f5f75c6b777 Mon Sep 17 00:00:00 2001 From: Francisco-Xiq Date: Sun, 17 May 2026 20:30:59 -0300 Subject: [PATCH 06/11] tests/integration/apache2_site/tasks/main.yml: remove blank line --- tests/integration/targets/apache2_site/tasks/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/targets/apache2_site/tasks/main.yml b/tests/integration/targets/apache2_site/tasks/main.yml index 3992755dee..feb2f976ff 100644 --- a/tests/integration/targets/apache2_site/tasks/main.yml +++ b/tests/integration/targets/apache2_site/tasks/main.yml @@ -37,4 +37,3 @@ - name: ensure that all test sites are disabled again ansible.builtin.assert: that: sites_before.stdout == sites_after.stdout - From 8c2db3bdff6bc775c933ad4a12fc8f3dc316cfab Mon Sep 17 00:00:00 2001 From: Francisco-Xiq Date: Sun, 17 May 2026 20:40:37 -0300 Subject: [PATCH 07/11] tests/integration/targets/apache2_site/tasks/main.yml: remove unncessary line --- tests/integration/targets/apache2_site/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/targets/apache2_site/tasks/main.yml b/tests/integration/targets/apache2_site/tasks/main.yml index feb2f976ff..f4bc089d97 100644 --- a/tests/integration/targets/apache2_site/tasks/main.yml +++ b/tests/integration/targets/apache2_site/tasks/main.yml @@ -11,7 +11,7 @@ - name: test apache2_site when: ansible_facts.os_family == 'Debian' - + block: - name: get list of enabled sites before tests ansible.builtin.command: ls /etc/apache2/sites-enabled/ From 0d4dd9054d5b32031751fcfd4c32b64b0a5c9663 Mon Sep 17 00:00:00 2001 From: Francisco Pereira <113396399+Francisco-xiq@users.noreply.github.com> Date: Sun, 17 May 2026 21:13:32 -0300 Subject: [PATCH 08/11] Update plugins/modules/apache2_site.py Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> --- plugins/modules/apache2_site.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/apache2_site.py b/plugins/modules/apache2_site.py index ba436c6590..ffa73dece3 100644 --- a/plugins/modules/apache2_site.py +++ b/plugins/modules/apache2_site.py @@ -14,6 +14,7 @@ short_description: Enables/disables a site of the Apache2 webserver description: - Enables or disables a specified site of the Apache2 webserver. - Uses C(a2ensite) and C(a2dissite) under the hood. +version_added: 13.0.0 notes: - This module is only available on Debian/Ubuntu-based systems, as it depends on C(a2ensite) and C(a2dissite). From 10bbd08501709d23bb8dfd6a9088450860269847 Mon Sep 17 00:00:00 2001 From: Francisco Pereira <113396399+Francisco-xiq@users.noreply.github.com> Date: Mon, 25 May 2026 11:03:17 -0300 Subject: [PATCH 09/11] Update plugins/modules/apache2_site.py Co-authored-by: Felix Fontein --- plugins/modules/apache2_site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/apache2_site.py b/plugins/modules/apache2_site.py index ffa73dece3..89491214a2 100644 --- a/plugins/modules/apache2_site.py +++ b/plugins/modules/apache2_site.py @@ -14,7 +14,7 @@ short_description: Enables/disables a site of the Apache2 webserver description: - Enables or disables a specified site of the Apache2 webserver. - Uses C(a2ensite) and C(a2dissite) under the hood. -version_added: 13.0.0 +version_added: 13.1.0 notes: - This module is only available on Debian/Ubuntu-based systems, as it depends on C(a2ensite) and C(a2dissite). From 23242ec5916bd182015e896460f704f9f89c3735 Mon Sep 17 00:00:00 2001 From: Francisco Pereira <113396399+Francisco-xiq@users.noreply.github.com> Date: Mon, 25 May 2026 11:04:25 -0300 Subject: [PATCH 10/11] Update plugins/modules/apache2_site.py Update available to supported Co-authored-by: Felix Fontein --- plugins/modules/apache2_site.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/apache2_site.py b/plugins/modules/apache2_site.py index 89491214a2..0907b61e62 100644 --- a/plugins/modules/apache2_site.py +++ b/plugins/modules/apache2_site.py @@ -16,7 +16,7 @@ description: - Uses C(a2ensite) and C(a2dissite) under the hood. version_added: 13.1.0 notes: - - This module is only available on Debian/Ubuntu-based systems, + - This module is only supported on Debian/Ubuntu-based systems, as it depends on C(a2ensite) and C(a2dissite). extends_documentation_fragment: - community.general._attributes From f75e8d5a5419383f166f36c0a555bc79f6a53085 Mon Sep 17 00:00:00 2001 From: Francisco Pereira <113396399+Francisco-xiq@users.noreply.github.com> Date: Mon, 25 May 2026 11:24:53 -0300 Subject: [PATCH 11/11] Refactor test site configuration tasks in YAML --- .../targets/apache2_site/tasks/actualtest.yml | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/integration/targets/apache2_site/tasks/actualtest.yml b/tests/integration/targets/apache2_site/tasks/actualtest.yml index 3a12bae737..6b8ce14b8f 100644 --- a/tests/integration/targets/apache2_site/tasks/actualtest.yml +++ b/tests/integration/targets/apache2_site/tasks/actualtest.yml @@ -3,7 +3,7 @@ # 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 test site config +- name: Create test site config ansible.builtin.copy: dest: /etc/apache2/sites-available/ansible_test_site.conf content: | @@ -12,73 +12,73 @@ DocumentRoot /var/www/html -- name: enable test site +- name: Enable test site community.general.apache2_site: name: ansible_test_site state: present register: enable_first -- name: ensure changed on first enable +- name: Ensure changed on first enable ansible.builtin.assert: that: - enable_first is changed -- name: enable test site again (idempotency check) +- name: Enable test site again (idempotency check) community.general.apache2_site: name: ansible_test_site state: present register: enable_second -- name: ensure idempotency on enable +- name: Ensure idempotency on enable ansible.builtin.assert: that: - enable_second is not changed -- name: disable test site +- name: Disable test site community.general.apache2_site: name: ansible_test_site state: absent register: disable_first -- name: ensure changed on first disable +- name: Ensure changed on first disable ansible.builtin.assert: that: - disable_first is changed -- name: disable test site again (idempotency check) +- name: Disable test site again (idempotency check) community.general.apache2_site: name: ansible_test_site state: absent register: disable_second -- name: ensure idempotency on disable +- name: Ensure idempotency on disable ansible.builtin.assert: that: - disable_second is not changed -- name: enable test site in check_mode +- name: Enable test site in check_mode community.general.apache2_site: name: ansible_test_site state: present check_mode: true register: check_mode_result -- name: ensure check_mode reports changed +- name: Ensure check_mode reports changed ansible.builtin.assert: that: - check_mode_result is changed -- name: ensure check_mode did not actually enable the site +- name: Ensure check_mode did not actually enable the site ansible.builtin.stat: path: /etc/apache2/sites-enabled/ansible_test_site.conf register: site_stat -- name: assert symlink was not created in check_mode +- name: Assert symlink was not created in check_mode ansible.builtin.assert: that: - not site_stat.stat.exists -- name: remove test site config +- name: Remove test site config ansible.builtin.file: path: /etc/apache2/sites-available/ansible_test_site.conf state: absent