1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-06-12 02:55:29 +00:00

apache2_site: apply review suggestions

This commit is contained in:
Francisco-Xiq 2026-05-17 20:27:34 -03:00
parent 7156a4b8f7
commit deccd7a02e
3 changed files with 12 additions and 11 deletions

View file

@ -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)

View file

@ -4,3 +4,8 @@
azp/posix/3
destructive
skip/rhel
skip/freebsd
skip/macos
skip/alpine

View file

@ -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