GitLab upgraded to 13.0.0-ee.0 - changelog: https://gitlab.com/gitlab-org/gitlab/blob/master/CHANGELOG-EE.md

Unverified Commit c00b476f authored by John Roesler's avatar John Roesler Committed by GitHub

Add 'template_cookbook' property to apache2_module (#673)

* Add template_cookbook param to apache2_module
Allows specifying a cookbook other than apache2 to pull a module.conf template from.
This feature is in the documentation for _module, but was not actually implemented.

* Add test for _module template_cookbook funtionality
- Add new module_template test cookbook recipe
- Add new module_template kitchen suite
- Add 'apt' cookbook dependency for debian/ubuntu suites converge error

* cookstyle fixes

* Update documentation for _module

* Update _module documentation to include missing properties

* markdown lint fix

* add new kitchen suite to CI list
parent 5299eadc
......@@ -51,6 +51,7 @@ jobs:
- 'basic-site'
- 'ssl'
- 'ports'
- 'module-template'
fail-fast: false
steps:
......
# apache2_module
Enable or disable an Apache module in `#{node['apache']['dir']}/mods-available` by calling `a2enmod` or `a2dismod` to manage the symbolic link in `#{node['apache']['dir']}/mods-enabled`. If the module has a configuration file, a template should be created in the cookbook where the definition is used. See **Examples**.
Enable or disable an Apache module in `#{apache_dir/mods-available` by calling `a2enmod` or `a2dismod` to manage the symbolic link in `#{apache_dir}/mods-enabled`. If the module has a configuration file, a template should be created in the cookbook where the definition is used. See **Examples**.
## Properties
| Name | Type | Default | Description |
| ----------------- | ------- | ------------------------- | ----------------------------------------------------------------------------------------------------------- |
| name | String | | Name of the module enabled or disabled with the `a2enmod` or `a2dismod` scripts. |
| identifier | String | `#{name}_module` | String to identify the module for the `LoadModule` directive |
| template_cookbook | String | apache2 | Cookbook to source the template from. Override this to provide your own template. |
| conf | Boolean | has_config? | The default is set by the config_file? helper. Override to set whether the module should have a config file |
| Name | Type | Default | Description |
| ----------------- | ------- | ------------------------- | ------------------------------------------------------------------------------------------------------------ |
| name | String | | Name of the module enabled or disabled with the `a2enmod` or `a2dismod` scripts. |
| mod_name | String | `#mod_{name}.so` | Filename of the module. Override if the module has a different filename the the default. |
| identifier | String | `#{name}_module` | String to identify the module for the `LoadModule` directive. |
| conf | Boolean | has_config? | The default is set by the config_file? helper. Override to set whether the module should have a config file. |
| template_cookbook | String | apache2 | Cookbook to source the template from. Override this to provide your own template. |
| mod_conf | Hash | {} | Varables to pass to the config file template. |
## Examples
......@@ -35,4 +37,13 @@ apache2_module "disabled_module" do
end
```
Enable a module with a custom template from the `foo` cookbook:
```ruby
apache2_module "module_name" do
conf true
template_cookbook 'foo'
end
```
See the recipes directory for many more examples of `apache2_module`.
......@@ -37,3 +37,6 @@ suites:
- name: ports
run_list:
- recipe[test::ports]
- name: module_template
run_list:
- recipe[test::module_template]
......@@ -14,12 +14,16 @@ property :identifier, String,
property :mod_conf, Hash,
default: {},
description: 'Pass properties to apache2_mod_<name>'
description: 'Pass properties to apache2_mod_<name> and config file template'
property :conf, [true, false],
default: lazy { config_file?(name) },
description: 'The default is set by the config_file? helper. Override to set whether the module should have a config file'
property :template_cookbook, String,
default: '',
description: 'Cookbook to source the config file template from'
property :apache_service_notification, Symbol,
equal_to: %i( reload restart ),
default: :reload,
......@@ -28,8 +32,17 @@ property :apache_service_notification, Symbol,
action :enable do
# Create apache2_mod_resource if we want it configured
if new_resource.conf
declare_resource("apache2_mod_#{new_resource.name}".to_sym, 'default') do
new_resource.mod_conf.each { |k, v| send(k, v) }
# manage template directly if using template from external cookbook since no mod_ resource for it, probably
if !new_resource.template_cookbook.empty?
template ::File.join(apache_dir, 'mods-available', "#{new_resource.name}.conf") do
source "mods/#{new_resource.name}.conf.erb"
cookbook new_resource.template_cookbook
variables new_resource.mod_conf
end
else
declare_resource("apache2_mod_#{new_resource.name}".to_sym, 'default') do
new_resource.mod_conf.each { |k, v| send(k, v) }
end
end
end
......
......@@ -6,3 +6,4 @@ license 'Apache-2.0'
description 'Testing cookbook for apache2'
version '0.0.1'
depends 'apache2'
depends 'apt'
apache2_install 'default'
service 'apache2' do
extend Apache2::Cookbook::Helpers
service_name lazy { apache_platform_service_name }
supports restart: true, status: true, reload: true
action [:start, :enable]
end
apache2_module 'info' do
conf true
template_cookbook 'test'
end
<IfModule mod_info.c>
<Location /server-info>
# test cookbook custom template
SetHandler server-info
Require local
Require ip 127.0.0.1 ::1
</Location>
</IfModule>
include_controls 'apache2-integration-tests' do
skip_control 'welcome-page'
end
control 'custom template' do
impact 1
desc 'mod_info.conf should be from custom template'
case os['family']
when 'debian', 'suse'
describe file('/etc/apache2/mods-available/info.conf') do
its('content') { should match(/# test cookbook custom template/) }
end
when 'freebsd'
describe file('/usr/local/etc/apache24/mods-available/info.conf') do
its('content') { should match(/# test cookbook custom template/) }
end
else
describe file('/etc/httpd/mods-available/info.conf') do
its('content') { should match(/# test cookbook custom template/) }
end
end
end
---
name: apache2-integration-tests
title: Integration tests for apache2 cookbook
summary: This InSpec profile contains integration tests for apache2 cookbook
supports:
- os-family: linux
- os-family: bsd
depends:
- name: apache2-integration-tests
path: test/integration/default
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment