Remove value from hash Puppet

Viewed 5377

I have the following params in hiera:

base::users:
  john@example.com:
    ensure: present
    user: john
    sudo: true
    type: ssh-rsa
    key: AAAAB3NzaC1yc2EAAAABJ

in puppet i'm getting the following hash:

 {john@example.com => {ensure => present, user => john, sudo => true, type => ssh-rsa, key => AAAAB3NzaC1yc2EAAAABJ}}

Then i'm calling create resources to create appropriate authorized_keys file:

create_resources('ssh_authorized_key', $users)

but it doesn't work because i have added new parameter 'sudo' and before calling create_resources I want to remove this key from hash and operate in another resource.

I've tried the next step to remove it:

$users_filtered = $users.each |$k, $v| { $v.delete['sudo'] }

i'm getting the next error:

Error while evaluating a Function Call, delete(): Wrong number of arguments given 1 for 2.

As I understand puppet tried to use 'delete' function from stdlib module. But i have also tried:

$users_filtered = $users.each |$k, $v| { delete($users, $v['sudo'] }

But it doesn't work. Appreciate any help

2 Answers

Since Puppet 4.0.0, the minus (-) operator deletes values from arrays and deletes keys from a hash:

['a', 'b', 'c', 'b'] - 'b'
# would return ['a', 'c']

{'a'=>1,'b'=>2,'c'=>3} - ['b','c'])
# would return {'a' => '1'}

https://github.com/puppetlabs/puppetlabs-stdlib#delete

Related