Hi Manuela,
On 30 Mar 2016, at 12:51, 'Manuela Mueller' via Puppet Users
<[email protected]> wrote:
> Dear All,
>
> I'm trying to set up a small module in order to test defined resource types.
> Module should create 2 users, data are in host specific yaml file pieps.yaml.
> When I try to apply the module I receive the following error message:
>
> [root@pieps modules]# puppet apply --noop --modulepath=./
> deftype_users_test/tests/init.pp
> Error: Evaluation Error: The value 'name' cannot be converted to Numeric. at
> /root/Desktop/testing/modules/deftype_users_test/manifests/init.pp:3:40 on
> node pieps.localdomain
>
> As I'm just beginning to learn Puppet, I have no idea where the error is.
> Any help would be greatly appreciated.
>
> Thank you very much and have a nice day,
>
> Manula Atoui
You want Puppet to do automatic data lookup for the class ‘deftype_users_test’
parameter.
In this case the hiera key has to follow naming convention:
<classname>::<parametername>
in your case:
deftyp_users_test::user list:
‘jill’:
uid: 1000
‘jack’:
uid: 1001
Within your puppet class you iterate over the hash:
class deftype_users_test (
Hash $userlist
){
$userlist.each | String $key, Hash $value| {
notify { “User with name: ${key} and hid ${value[uid]}”: }
}
}
hth,
Martin
>
> Hiera configuration:
> ======================
> puppet master --configprint all
> ...
> hiera_config = /etc/puppetlabs/code/hiera.yaml
>
> cat /etc/puppetlabs/code/hiera.yaml
>
> hiera.yaml:
> ---
>
> :backends:
> - yaml
> :hierarchy:
> # orig - "nodes/%{::trusted.certname}"
> - "hostname/%{facts.hostname}"
> - "os/%{facts.osfamily}"
> - common
>
> :yaml:
> :datadir: /etc/puppetlabs/code/hieradata
>
>
> I set up a yaml file for host pieps:
> /etc/puppetlabs/code/hieradata/hostname/pieps.yaml
>
> --- # start yaml file
> message: "sample message from hiera in pieps.yaml"
> # deftype_users_test, defined resource type 'create'
> user:
> jill:
> uid: 10000
> comment: 'user jill, test defined resource type'
> jack:
> uid: 10001
> comment: 'user jack, test defined resource type'
>
> Structure module deftype_users_test
> =====================================
> [root@pieps deftype_users_test]# tree
> .
> ├── manifests
> │ ├── create.pp
> │ ├── create.pp~
> │ ├── init.pp
> │ └── init.pp~
> └── tests
> └── init.pp
>
> 2 directories, 5 files
>
> [root@pieps deftype_users_test]# cat manifests/init.pp
> class deftype_users_test( Array[Hash] $userlist = [] ) {
> userlist.each |$user| {
> deftype_users_test::create { $user['name']:
> uid => $user['uid'],
> comment => $user['comment'],
> } # end call defined resource type 'create'
> } # end lambda block
> } # end class deftype_users_test
>
>
> [root@pieps deftype_users_test]# cat manifests/create.pp
> define deftype_users_test::create(
> Integer $uid,
> String $comment,
> ) {
> user { $title:
> uid => $uid,
> comment => $comment,
> }
> } # end defined resource type 'create'
>
> [root@pieps deftype_users_test]# cat tests/init.pp
> include deftype_users_test
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/cb8fcf42-80a7-499e-841d-5bda1b3a2369%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/4F30B89C-CB70-478B-B9A6-2595933DC403%40gmail.com.
For more options, visit https://groups.google.com/d/optout.