Ask Your Question
0

Pass Parameter to Puppet Module at Runtime

asked 2016-08-25 04:21:12 -0500

ChetAn P gravatar image

updated 2016-08-25 05:42:54 -0500

Hi all, Is it possible to pass the parameter in Puppet ? For eg , If i have to create Disk partition module, so how can i pass the 1. "Partition name" 2. "Size of partition" parameter through Puppet Module each time when i run module.

Lot's of my modules use parameters. So how do I test the module with different parameters without the need to hardcode them?

edit retag flag offensive close merge delete

Comments

How you are calling your module (using site.pp)? Are you using hiera to define your data/parameters?

rajeevsharma gravatar imagerajeevsharma ( 2016-08-25 06:50:52 -0500 )edit

Thanks Rajeev... Yes I am calling from site.pp. Is there any other way to call it ? How to pass parameter like "Puppet agent -t Test /app 50GB".. Can we do this ? or any other way to do ? Please help me

ChetAn P gravatar imageChetAn P ( 2016-08-25 07:46:39 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-08-27 09:23:21 -0500

natemccurdy gravatar image

You can't pass parameters to classes from puppet agent -t. You can only pass parameters by setting them when you declare a class in your Puppet code.

Also, if this is a module you're writing yourself, you'll need to define the parameters first, like this:

```

class foo (
  $value1 = 'something',     # This is a parameter
  $value2 = 1234,            # This is the second parameter
) {

  file { '/tmp/test.txt':
    ensure => file,
    content => $value1,
  }

}

$value1 and $value2 are parameters with default values of something and 1234. They become variables that you can use in your code.

When you go to declare the foo class, or use it, you pass in values for those paramers if you want to use a different value:

class { 'foo':
  value2 => 5798,
}
edit flag offensive delete link more

Comments

Yeah, the only way I see for considering varying data during the runtime would be via facts.

Kai Burghardt gravatar imageKai Burghardt ( 2016-09-03 19:03:44 -0500 )edit
0

answered 2016-08-25 14:55:38 -0500

rajeevsharma gravatar image

updated 2016-08-25 15:10:08 -0500

Hi, Puppet script which is helpful to trigger puppet agent run on target node, it does not work like a parameterized script. Reason: it requests for a code from puppet master called cataog which is getting compiled on master itself using the code and data you keep on master node.

If you want to execute your code in parameterized way you can use classes with parameters. Values for those parameters can be set when you declare your class in site.pp.

As an option you can use hiera as well if you would like to keep your data in yaml files. For example: https://docs.puppet.com/hiera/3.2/com... Hope this helps.

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-08-25 04:21:12 -0500

Seen: 947 times

Last updated: Aug 25 '16