Ask Your Question
0

Problems with each loop and future parser

asked 2016-09-19 15:34:29 -0500

prototyp gravatar image

Hey there,

I am writing a small init puppet config to configure my servers without puppet master. For creating user accounts I want iterate via an each loop over a array of user names defined in a hiera file. Without running the future parser my example each loop is not working and if i use it my data in the yaml file cant be read.

I installed the the puppet-common pkt (vers: 3.8.7-1puppetlabs1) on Ubuntu 12.04. Should each not run in this version without future parser?

The class iterating over the users:

#modules/manage_users/manifests/init.pp
class manage_users($users,){
group { 'test':
  ensure => 'present'
}
['a','b','c'].each |Integer $index, String $value| { notice("${index} = ${value}") }

#each($users) |$user| {
#notify{"user: ${user}",}
#  group {"${user}":
#    ensure => 'present'
#  }
#  user { "${user}" :
#    ensure => 'present',
#    groups => [$user, test],
#    home   => "/home/${user}",
#    shell  => '/bin/bash',
#  }
}

My hiera.yaml:

:backends:
    - yaml
:yaml:
  :datadir: /etc/puppet/hieradata

:hierarchy:
  - lpkb

The yaml with the data:

#hieradata/lpkb.yaml
manage-users::users:
  - user1
  - user2
manage-users::test: test

puppet.conf:

[main]
logdir=/var/log/puppet
vardir=/var/lib/puppet
ssldir=/var/lib/puppet/ssl
rundir=/var/run/puppet

If I run without future parser:

puppet apply manifests/site.pp

Error:

Error: Syntax error at '['; expected ']' at /etc/puppet/modules/manage_users/manifests/init.pp:7 on node vps1234.localhost.local
Error: Syntax error at '['; expected ']' at /etc/puppet/modules/manage_users/manifests/init.pp:7 on node vps1234.localhost.local

With future parser:

puppet apply --parser=future manifests/site.pp

Error: Evaluation Error: Error while evaluating a Function Call, Must pass users to Class[Manage_users] at /etc/puppet/manifests/site.pp:3:5 on node vps1234.localhost.local
Error: Evaluation Error: Error while evaluating a Function Call, Must pass users to Class[Manage_users] at /etc/puppet/manifests/site.pp:3:5 on node vps1234.localhost.local

What am I doing wrong?

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
0

answered 2016-09-20 16:14:21 -0500

prototyp gravatar image

Ok found a solution for the mentioned issues:

Via rvm I was able to install the newest puppet 4 version with support for the great each function! I still dont understand why this was not possible even while using the ppa from puppet labs...

With future parser it also had worked. My hiera config file was just wrong. class used to adress my vars was wrong. Changed it from manage-user:users to manage_users::users and future parser worked well.

I also changed my puppet call to be precise:

puppet apply --hiera_config=hiera.yaml --modulepath=modules/ manifests/site.pp

Hope that helps somebody running into same issues.

edit flag offensive delete link more

Comments

Oh yea, I hadn't even noticed.. you can't use dashes in variables or any names/paths on the autoloader. Good catch!

DarylW gravatar imageDarylW ( 2016-09-20 19:16:10 -0500 )edit
0

answered 2016-09-19 15:48:35 -0500

DarylW gravatar image

updated 2016-09-19 15:51:12 -0500

each is only available with the future parser, or puppet 4.x. Prior to that, you needed to construct 'define' statements that could iterate over arrays of namevars.

https://docs.puppet.com/puppet/latest...

Note from the bottom of that section..

•Since 4.0.0


•Type: rvalue

I found a similar question and response here that may be of help... https://ask.puppet.com/question/24567/probelm-getting-each-function-to-work/

edit flag offensive delete link more

Comments

But why is my hiera structure with the future parser not working? I installed puppet after pulling the pc1 deb release pkt with wget so I should have installed puppet 4 already or?

prototyp gravatar imageprototyp ( 2016-09-20 11:41:13 -0500 )edit

I didn't get a chance to exaustivly test it. I tested using puppet apply --parser=future with your above [a,b,c] example on puppet 3.7.4 and that worked. You may not have hiera correctly configured.

DarylW gravatar imageDarylW ( 2016-09-20 12:13:59 -0500 )edit

if you are just calling puppet apply, you need to pass in a --hieraconfig option that points to your correct hiera.yaml file (that has a reference to the correct data directory)

DarylW gravatar imageDarylW ( 2016-09-20 12:15:02 -0500 )edit

Also, I don't understand the downvote, you asked "Should each not run in this version without future parser?", and that is what I answered above

DarylW gravatar imageDarylW ( 2016-09-20 12:16:19 -0500 )edit

got the same error when using the --hiera_config=hiera.yaml option. maybe the best solution is to just upgrade to puppet 4 but how can I do that? I think i have allready the newest version. I installed the puppetlabs-release-pc1-precise.deb pkt and should use with that the puppet repo.

prototyp gravatar imageprototyp ( 2016-09-20 12:56:44 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-09-19 15:34:29 -0500

Seen: 207 times

Last updated: Sep 20 '16