Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/json.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$data = {
"bar" => {
"baz" => "foo",
"moo" => 1,
"cow" => "1",
}
}


$symbols = {
":bar" => {
"baz" => "foo",
"moo" => 1,
":cow" => "1",
}
}


hash_file { '/tmp/hash.json':
value => $data,
provider => 'json',
}

hash_file { '/tmp/symbols.json':
value => $symbols,
provider => 'json',
}
27 changes: 27 additions & 0 deletions examples/yaml.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$data = {
"bar" => {
"baz" => "foo",
"moo" => 1,
"cow" => "1",
}
}


$symbols = {
":bar" => {
"baz" => "foo",
"moo" => 1,
":cow" => "1",
}
}


hash_file { '/tmp/hash.yaml':
value => $data,
provider => 'yaml',
}

hash_file { '/tmp/symbols.yaml':
value => $symbols,
provider => 'yaml',
}
21 changes: 21 additions & 0 deletions lib/puppet/type/hash_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@
raise ArgumentError, "Value is not of type Hash"
end
end

# convert strings like ":thing" to a symbolic representation, :thing
# This is needed to manage symbol keys in yaml files.
munge do |value|
return value unless resource[:provider] == :yaml
resource.symbolize_keys(value)
end
end

def symbolize_keys(data)
data.each_with_object({}) do |item, memo|
key, val = item

val = symbolize_keys(val) if val.class == Hash

if key =~ /^:/
memo[key[1..-1].to_sym] = val
else
memo[key] = val
end
end
end

end