From fcc2cd556abe5c51cd4e8da1b7e7b6c62dc0d1e5 Mon Sep 17 00:00:00 2001 From: Fredrik Eriksson Date: Mon, 6 Feb 2017 17:05:02 +0100 Subject: [PATCH] Add apply_prefix argument to service object to allow prefixing services added with apply loops as per issue #227 --- manifests/object.pp | 5 +++++ manifests/object/service.pp | 6 ++++++ templates/object.conf.erb | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/manifests/object.pp b/manifests/object.pp index 635b32334..0efefd626 100644 --- a/manifests/object.pp +++ b/manifests/object.pp @@ -21,6 +21,9 @@ # [*apply_target*] # An object type on which to target the apply rule. Valid values are `Host` and `Service`. Defaults to `Host`. # +# [*apply_prefix*] +# An optional name prefix to use when using a loop apply statement. +# # [*import*] # A sorted list of templates to import in this object. Defaults to an empty array. # @@ -54,6 +57,7 @@ $template = false, $apply = false, $apply_target = undef, + $apply_prefix = undef, $import = [], $assign = [], $ignore = [], @@ -91,6 +95,7 @@ unless is_bool($apply) { validate_re($apply, '^.+\s+(=>\s+.+\s+)?in\s+.+$') } if $apply_target { validate_re($apply_target, ['^Host$', '^Service$'], "${apply_target} isn't supported. Valid values are 'Host' and 'Service'.") } + if $apply_prefix { validate_string($apply_prefix) } validate_array($import) validate_array($assign) validate_array($ignore) diff --git a/manifests/object/service.pp b/manifests/object/service.pp index d380b2ee2..d810fa663 100644 --- a/manifests/object/service.pp +++ b/manifests/object/service.pp @@ -109,6 +109,9 @@ # Dispose an apply instead an object if set to 'true'. Value is taken as statement, # i.e. 'vhost => config in host.vars.vhosts'. Defaults to false. # +# [*apply_prefix*] +# An optional name prefix to use when using a loop apply statement. +# # [*assign*] # Assign user group members using the group assign rules. # @@ -185,6 +188,7 @@ $icon_image = undef, $icon_image_alt = undef, $apply = false, + $apply_prefix = undef, $assign = [], $ignore = [], $import = [], @@ -231,6 +235,7 @@ if $action_url { validate_string ($action_url) } if $icon_image { validate_absolute_path ($icon_image) } if $icon_image_alt { validate_string ($icon_image_alt) } + if $apply_prefix { validate_string($apply_prefix) } # compose the attributes @@ -271,6 +276,7 @@ import => $import, apply => $apply, apply_target => 'Host', + apply_prefix => $apply_prefix, assign => $assign, ignore => $ignore, template => $template, diff --git a/templates/object.conf.erb b/templates/object.conf.erb index 24f8ad3fa..e0a3f24d2 100644 --- a/templates/object.conf.erb +++ b/templates/object.conf.erb @@ -1,5 +1,5 @@ -<% if @apply.is_a?(String) %>apply <%= @object_type -%> for (<%= @apply %>) to <%= @apply_target -%> { +<% if @apply.is_a?(String) %>apply <%= @object_type -%> <% if @apply_prefix %>"<%= @apply_prefix %>" <% end %>for (<%= @apply %>) to <%= @apply_target -%> { <% else -%> <% if @apply %>apply<% else -%> <% if @template %>template<% else %>object<% end -%>