mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-07-06 10:38:54 +00:00
feat: new module apache2_site - enable/disable Apache2 Sites on Debian Systems
This commit is contained in:
parent
eb69d25e45
commit
f9a5afccfe
6 changed files with 270 additions and 0 deletions
6
tests/integration/targets/apache2_site/aliases
Normal file
6
tests/integration/targets/apache2_site/aliases
Normal file
|
|
@ -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
|
||||
7
tests/integration/targets/apache2_site/meta/main.yml
Normal file
7
tests/integration/targets/apache2_site/meta/main.yml
Normal file
|
|
@ -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
|
||||
103
tests/integration/targets/apache2_site/tasks/actualtest.yml
Normal file
103
tests/integration/targets/apache2_site/tasks/actualtest.yml
Normal file
|
|
@ -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: |
|
||||
<VirtualHost *:80>
|
||||
ServerName ansible-test.local
|
||||
DocumentRoot /var/www/html
|
||||
</VirtualHost>
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# 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
|
||||
40
tests/integration/targets/apache2_site/tasks/main.yml
Normal file
40
tests/integration/targets/apache2_site/tasks/main.yml
Normal file
|
|
@ -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
|
||||
Loading…
Add table
Add a link
Reference in a new issue