Skip to content

Commit cb57ad5

Browse files
committed
Allow native types to handle a list of tags
make it possible to concatenate fragments identified by different tags into a file; allow parameter "tag" of type "concat_file" to be a string or array of strings therefore additionally handle nonexistent tags (as being optional in both native types) correctly
1 parent bb53e58 commit cb57ad5

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

lib/puppet/type/concat_file.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,30 @@
88
Puppet::Type.newtype(:concat_file) do
99
@doc = <<-DOC
1010
@summary
11-
Generates a file with content from fragments sharing a common unique tag.
11+
Generates a file with content from fragments sharing a single or a list of common unique tag(s).
1212
1313
@example
1414
Concat_fragment <<| tag == 'unique_tag' |>>
15+
Concat_fragment <<| tag == 'other_tag' |>>
1516
1617
concat_file { '/tmp/file':
1718
tag => 'unique_tag', # Optional. Default to undef
1819
path => '/tmp/file', # Optional. If given it overrides the resource name
1920
owner => 'root', # Optional. Default to undef
2021
group => 'root', # Optional. Default to undef
21-
mode => '0644' # Optional. Default to undef
22-
order => 'numeric' # Optional, Default to 'numeric'
22+
mode => '0644', # Optional. Default to undef
23+
order => 'numeric', # Optional, Default to 'numeric'
2324
ensure_newline => false # Optional, Defaults to false
2425
}
26+
concat_file { '/tmp/file2':
27+
tag => ['unique_tag', 'other_tag'],
28+
path => '/tmp/file2',
29+
owner => 'root',
30+
group => 'root',
31+
mode => '0644',
32+
order => 'numeric',
33+
ensure_newline => false
34+
}
2535
DOC
2636

2737
ensurable do
@@ -40,7 +50,7 @@ def exists?
4050
end
4151

4252
newparam(:tag) do
43-
desc 'Required. Specifies a unique tag reference to collect all concat_fragments with the same tag.'
53+
desc 'Specifies a single or a list of unique tag reference(s) to collect all concat_fragments with the same tag(s).'
4454
end
4555

4656
newparam(:path, namevar: true) do
@@ -194,7 +204,7 @@ def fragments
194204
next unless resource.is_a?(Puppet::Type.type(:concat_fragment))
195205

196206
if resource[:target] == self[:path] || resource[:target] == title ||
197-
(resource[:tag] && resource[:tag] == self[:tag])
207+
((resource[:tag] && self[:tag]) && (resource[:tag] == self[:tag] || self[:tag].include?(resource[:tag])))
198208
resource
199209
end
200210
}.compact

lib/puppet/type/concat_fragment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
next unless resource.is_a?(Puppet::Type.type(:concat_file))
7676

7777
resource[:path] == self[:target] || resource.title == self[:target] ||
78-
(resource[:tag] && resource[:tag] == self[:tag])
78+
((resource[:tag] && self[:tag]) && (resource[:tag] == self[:tag] || resource[:tag].include?(self[:tag])))
7979
end
8080

8181
if found.empty?

0 commit comments

Comments
 (0)