Skip to content

Commit

Permalink
Merge pull request #20 from flotho/IMP-more-flexible-vhosts
Browse files Browse the repository at this point in the history
[IMP]More flexible way to setup vhosts
  • Loading branch information
robertdebock committed Sep 24, 2023
2 parents 2f2a5ca + 59fd0dd commit eeee31a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 18 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Install and configure httpd on your system.

|GitHub|GitLab|Quality|Downloads|Version|
|------|------|-------|---------|-------|
|[![github](https://github.com/robertdebock/ansible-role-httpd/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-httpd/actions)|[![gitlab](https://gitlab.com/robertdebock-iac/ansible-role-httpd/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-httpd)|[![quality](https://img.shields.io/ansible/quality/21855)](https://galaxy.ansible.com/robertdebock/httpd)|[![downloads](https://img.shields.io/ansible/role/d/21855)](https://galaxy.ansible.com/robertdebock/httpd)|[![Version](https://img.shields.io/github/release/robertdebock/ansible-role-httpd.svg)](https://github.com/robertdebock/ansible-role-httpd/releases/)|
| GitHub | GitLab | Quality | Downloads | Version |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [![github](https://github.com/robertdebock/ansible-role-httpd/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-httpd/actions) | [![gitlab](https://gitlab.com/robertdebock-iac/ansible-role-httpd/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-httpd) | [![quality](https://img.shields.io/ansible/quality/21855)](https://galaxy.ansible.com/robertdebock/httpd) | [![downloads](https://img.shields.io/ansible/role/d/21855)](https://galaxy.ansible.com/robertdebock/httpd) | [![Version](https://img.shields.io/github/release/robertdebock/ansible-role-httpd.svg)](https://github.com/robertdebock/ansible-role-httpd/releases/) |

## [Example Playbook](#example-playbook)

Expand Down Expand Up @@ -132,6 +132,9 @@ httpd_additionnal_modules: []

apache_global_vhost_settings: |
DirectoryIndex index.php index.html
# Path to the template used for vhosts. usefull to override the conf by your own setup
vhost_conf_template: vhost.conf.j2
```

## [Requirements](#requirements)
Expand All @@ -142,14 +145,14 @@ apache_global_vhost_settings: |

The following roles are used to prepare a system. You can prepare your system in another way.

| Requirement | GitHub | GitLab |
|-------------|--------|--------|
|[robertdebock.bootstrap](https://galaxy.ansible.com/robertdebock/bootstrap)|[![Build Status GitHub](https://github.com/robertdebock/ansible-role-bootstrap/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-bootstrap/actions)|[![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-bootstrap/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-bootstrap)|
|[robertdebock.buildtools](https://galaxy.ansible.com/robertdebock/buildtools)|[![Build Status GitHub](https://github.com/robertdebock/ansible-role-buildtools/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-buildtools/actions)|[![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-buildtools/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-buildtools)|
|[robertdebock.epel](https://galaxy.ansible.com/robertdebock/epel)|[![Build Status GitHub](https://github.com/robertdebock/ansible-role-epel/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-epel/actions)|[![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-epel/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-epel)|
|[robertdebock.openssl](https://galaxy.ansible.com/robertdebock/openssl)|[![Build Status GitHub](https://github.com/robertdebock/ansible-role-openssl/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-openssl/actions)|[![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-openssl/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-openssl)|
|[robertdebock.python_pip](https://galaxy.ansible.com/robertdebock/python_pip)|[![Build Status GitHub](https://github.com/robertdebock/ansible-role-python_pip/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-python_pip/actions)|[![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-python_pip/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-python_pip)|
|[robertdebock.selinux](https://galaxy.ansible.com/robertdebock/selinux)|[![Build Status GitHub](https://github.com/robertdebock/ansible-role-selinux/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-selinux/actions)|[![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-selinux/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-selinux)|
| Requirement | GitHub | GitLab |
| ----------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [robertdebock.bootstrap](https://galaxy.ansible.com/robertdebock/bootstrap) | [![Build Status GitHub](https://github.com/robertdebock/ansible-role-bootstrap/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-bootstrap/actions) | [![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-bootstrap/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-bootstrap) |
| [robertdebock.buildtools](https://galaxy.ansible.com/robertdebock/buildtools) | [![Build Status GitHub](https://github.com/robertdebock/ansible-role-buildtools/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-buildtools/actions) | [![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-buildtools/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-buildtools) |
| [robertdebock.epel](https://galaxy.ansible.com/robertdebock/epel) | [![Build Status GitHub](https://github.com/robertdebock/ansible-role-epel/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-epel/actions) | [![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-epel/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-epel) |
| [robertdebock.openssl](https://galaxy.ansible.com/robertdebock/openssl) | [![Build Status GitHub](https://github.com/robertdebock/ansible-role-openssl/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-openssl/actions) | [![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-openssl/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-openssl) |
| [robertdebock.python_pip](https://galaxy.ansible.com/robertdebock/python_pip) | [![Build Status GitHub](https://github.com/robertdebock/ansible-role-python_pip/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-python_pip/actions) | [![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-python_pip/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-python_pip) |
| [robertdebock.selinux](https://galaxy.ansible.com/robertdebock/selinux) | [![Build Status GitHub](https://github.com/robertdebock/ansible-role-selinux/workflows/Ansible%20Molecule/badge.svg)](https://github.com/robertdebock/ansible-role-selinux/actions) | [![Build Status GitLab](https://gitlab.com/robertdebock-iac/ansible-role-selinux/badges/master/pipeline.svg)](https://gitlab.com/robertdebock-iac/ansible-role-selinux) |

## [Context](#context)

Expand Down
6 changes: 6 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@ httpd_remove_example: no

httpd_additionnal_modules: []

httpd_custom_modules_to_activate_with_command: []

apache_global_vhost_settings: |
DirectoryIndex index.php index.html
vhost_conf_template: vhost.conf.j2

default_vhost_conf: default_vhost.conf
14 changes: 14 additions & 0 deletions tasks/assert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,17 @@
- httpd_additionnal_modules is defined
- httpd_additionnal_modules | type_debug == "list"
quiet: yes

- name: assert | Test if httpd_modules_to_activate_with_command is set correctly
ansible.builtin.assert:
that:
- httpd_modules_to_activate_with_command is defined
- httpd_modules_to_activate_with_command | type_debug == "list"
quiet: yes

- name: assert | Test if default_vhost_conf is set correctly
ansible.builtin.assert:
that:
- default_vhost_conf is defined
- default_vhost_conf is string
quiet: yes
10 changes: 10 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
- Test httpd configuration validity
- Restart httpd

- name: Activate httpd module | Debian
ansible.builtin.command:
cmd: "a2enmod {{ item }}"
changed_when: no
loop: "{{ httpd_modules_to_activate_with_command }}"
when:
- ansible_os_family == 'Debian'
notify:
- Test httpd configuration validity

- name: Import ssl.yml
ansible.builtin.import_tasks:
file: ssl.yml
Expand Down
3 changes: 1 addition & 2 deletions tasks/ssl.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: ssl | Install ssl packages
ansible.builtin.package:
name: "{{ httpd_ssl_packages }}"
Expand All @@ -17,7 +16,7 @@
- name: ssl | Configure redirect from http to https
ansible.builtin.template:
src: default_vhost.conf.j2
dest: "{{ httpd_config_directory }}/default_vhost.conf"
dest: "{{ httpd_config_directory }}/{{ default_vhost_conf }}"
mode: "0644"
notify:
- Test httpd configuration validity
Expand Down
5 changes: 2 additions & 3 deletions tasks/vhosts.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---

- name: vhosts | Create docroot
ansible.builtin.file:
path: "{{ item.documentroot }}"
Expand All @@ -15,8 +14,8 @@

- name: vhosts | Configure vhosts
ansible.builtin.template:
src: vhost.conf.j2
dest: "{{ httpd_config_directory }}/{{ item.name }}.conf"
src: "{{ vhost_conf_template }}"
dest: "{{ httpd_vhosts_directory }}/{{ item.name }}.conf"
mode: "0644"
loop: "{{ httpd_vhosts }}"
loop_control:
Expand Down
20 changes: 18 additions & 2 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ _httpd_packages:

httpd_packages: "{{ httpd_additionnal_modules + _httpd_packages[ansible_os_family] | default(_httpd_packages['default']) }}"

_httpd_modules_to_activate_with_command:
default: []
Debian:
- proxy
- proxy_http

httpd_modules_to_activate_with_command: "{{ httpd_custom_modules_to_activate_with_command + _httpd_modules_to_activate_with_command[ansible_os_family] | default(_httpd_modules_to_activate_with_command['default']) }}"

_httpd_ssl_packages:
default:
- mod_ssl
Expand Down Expand Up @@ -69,12 +77,20 @@ httpd_config_src: "{{ _httpd_config_src[ansible_os_family] }}"

_httpd_config_dest:
Alpine: "{{ httpd_server_root }}/httpd.conf"
Debian: "{{ httpd_server_root }}/httpd.conf"
Debian: "{{ httpd_server_root }}/apache2.conf"
RedHat: "{{ httpd_server_root }}/conf/httpd.conf"
Suse: "{{ httpd_server_root }}/httpd.conf"

httpd_config_dest: "{{ _httpd_config_dest[ansible_os_family] }}"

_httpd_vhosts_directory:
default: "{{ httpd_server_root }}/conf.d"
Alpine: "{{ httpd_server_root }}/conf.d"
Debian: "{{ httpd_server_root }}/sites-enabled"
Suse: "{{ httpd_server_root }}/conf.d"

httpd_vhosts_directory: "{{ _httpd_vhosts_directory[ansible_os_family] | default(_httpd_vhosts_directory['default']) }}"

# Some distributions have the "Listen" parameters somewhere else.
_httpd_ports_conf:
Debian: ports.conf
Expand All @@ -100,7 +116,7 @@ httpd_modules_path: "{{ _httpd_modules_path[ansible_os_family] | default(_httpd_
# This variable is used in handlers to test the configuration.
_httpd_binary:
default: httpd
Debian: apachectl
Debian: apache2ctl

httpd_binary: "{{ _httpd_binary[ansible_os_family] | default(_httpd_binary['default']) }}"

Expand Down

0 comments on commit eeee31a

Please sign in to comment.