-
-
Notifications
You must be signed in to change notification settings - Fork 881
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initial support for snippets #1231
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
class { 'nginx': | ||
snippets_dir => '/etc/nginx/snippets', | ||
} | ||
|
||
$snippet = @("SNIPPET"/L) | ||
location @custom_451_error { | ||
return 451; | ||
} | ||
| SNIPPET | ||
|
||
nginx::resource::snippet { 'test_snippet': | ||
raw_content => $snippet, | ||
} | ||
|
||
nginx::resource::server { 'test.local:8080': | ||
ensure => present, | ||
listen_port => 8080, | ||
server_name => ['test.local test'], | ||
include_files => ["${nginx::snippets_dir}/test_snippet.conf"], | ||
try_files => [ 'non-existant', '@custom_451_error'], | ||
} | ||
|
||
nginx::resource::server { 'test.local:8081': | ||
ensure => present, | ||
listen_port => 8081, | ||
server_name => ['test.local test'], | ||
include_files => ["${nginx::snippets_dir}/test_snippet.conf"], | ||
try_files => [ 'non-existant', '@custom_451_error'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# This definition creates a reusable config snippet that can be included by other resources | ||
# | ||
# @param ensure Enables or disables the specified snippet | ||
# @param owner Defines owner of the .conf file | ||
# @param group Defines group of the .conf file | ||
# @param mode Defines mode of the .conf file | ||
# @param raw_content Raw content that will be inserted into the snipped as-is | ||
|
||
define nginx::resource::snippet ( | ||
String[1] $raw_content, | ||
Enum['absent', 'present'] $ensure = 'present', | ||
String $owner = $nginx::global_owner, | ||
String $group = $nginx::global_group, | ||
Stdlib::Filemode $mode = $nginx::global_mode, | ||
) { | ||
if ! defined(Class['nginx']) { | ||
fail('You must include the nginx base class before using any defined resources') | ||
} | ||
|
||
$name_sanitized = regsubst($name, ' ', '_', 'G') | ||
$config_file = "${nginx::snippets_dir}/${name_sanitized}.conf" | ||
|
||
concat { $config_file: | ||
ensure => $ensure, | ||
owner => $owner, | ||
group => $group, | ||
mode => $mode, | ||
notify => Class['nginx::service'], | ||
require => File[$nginx::snippets_dir], | ||
} | ||
|
||
concat::fragment { "snippet-${name_sanitized}-header": | ||
target => $config_file, | ||
content => epp("${module_name}/snippet/snippet_header.epp", { 'raw_content' => $raw_content }), | ||
order => '001', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
|
||
describe 'nginx::resource::snippet' do | ||
on_supported_os.each do |os, facts| | ||
context "on #{os}" do | ||
let(:facts) do | ||
facts | ||
end | ||
let :title do | ||
'some_snippet' | ||
end | ||
|
||
let :pre_condition do | ||
'include nginx' | ||
end | ||
|
||
describe 'basic snippet' do | ||
let :params do | ||
{ | ||
raw_content: 'this is a test' | ||
} | ||
end | ||
|
||
it { is_expected.to contain_concat__fragment('snippet-some_snippet-header').with_target("/etc/nginx/snippets/#{title}.conf").with_content(%r{this is a test}) } | ||
it { is_expected.to contain_concat('/etc/nginx/snippets/some_snippet.conf') } | ||
it { is_expected.to compile.with_all_deps } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%- | String $raw_content, | ||
| -%> | ||
# MANAGED BY PUPPET | ||
|
||
<%= $raw_content %> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need a check in here to ensure that
$config_file
isn't already defined as a concat resource. If it is and you try to add another snippet to the same$config_file
, it will fail when it tries to create this resource.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this. $config_file contains the name of the defined resource, so it's already unique in the catalog.