Ask Your Question
0

How do you use a variable in a Puppet Manifest?

asked 2016-09-14 18:45:10 -0500

Conventional gravatar image

I am using the WSUS Module with Puppet Master on Centos 7.2. My Puppet Agent servers are running Windows Server 2012.

I want to use a manifest with a variable. However, when the Puppet Agent server has the puppet agent run, it displays "error 400, syntax error." I have tried re-writing the manifest and every variation I could think of. I keep getting some error.

Here is one example of a manifest:

class excellent {
    class { 'wsus_client':
       $cool = 'Saturday'
    server_url => 'http://acme.com',
    auto_update_option  => 'Scheduled'
    scheduled_install_day => $cool,
    scheduled_install_hour => 1,
}
}

I've tried assigning the variable in braces {}. I tried to use $LOAD_PATH, --custom-dir and FACTERLIB. But I could not figure out how to use any of these three.

I want to change the variable in one place and use it within the scope of its parent class. What should I do?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

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

DarylW gravatar image

updated 2016-09-14 22:01:25 -0500

If you want to access/modify a value in a class, the best way to do that is via parameters. There is a really good set of guides in this gitbook on Test Driven Puppet

You should create it as a parameter to your class, and set the value either by passing a value to it, or by filling in the value via Hiera's Automatic Parameter Lookup (APL)

class excellent(
  $cool = 'Saturday',
) {
  class { 'wsus_client':  
      server_url => 'http://acme.com',
      auto_update_option  => 'Scheduled'
      scheduled_install_day => $cool,
      scheduled_install_hour => 1,
    }
}
edit flag offensive delete link more
0

answered 2016-09-14 19:16:45 -0500

iamback gravatar image

can you define $cool where you have, just after the colon?

Move it outside of the inner class.

 class excellent {
   $cool = 'Saturday'
   class { 'wuss_client':
     server_url => 'http://acme.com',
     etc => 'other parts',
  }
}
edit flag offensive delete link more

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-14 18:45:10 -0500

Seen: 62 times

Last updated: Sep 14 '16