puppet apply manifest command line parameters

4,095 views
Skip to first unread message

Sachin Nikam

unread,
Dec 8, 2013, 10:31:27 PM12/8/13
to puppet...@googlegroups.com
I am newbie to puppet(versin 2.7) and came up with a manifest that contains some "exec" tasks. when I invoke the puppet apply <manifest>, I want to pass in some parameters specific to my application. How do I do that? I searched the online documentation but couldn't find any examples.
Regards
Sachin

Jake Lundberg

unread,
Dec 9, 2013, 2:46:17 PM12/9/13
to puppet...@googlegroups.com
I suppose it depends on how you structure your manifest.   We typically apply a manifest to a particular node when testing new manifests.   So something like:

site.pp:
node default {
  $param1 = "value1"
  $param2 = "value2"

  include exec_class
}

/etc/puppet/modules/exec_class/manifests/init.pp
class exec_class ( $param1, $param2) {

  exec { "do something" :
    command => "/usr/local/bin/exec_something.sh"
  }
}

# puppet apply --modulepath=/etc/puppet/modules site.pp

Jake Lundberg

unread,
Dec 9, 2013, 2:48:16 PM12/9/13
to puppet...@googlegroups.com
Oops, that should probably read:

exec { "do something" :
    command => "/usr/local/bin/exec_something.sh ${param1} ${param2}"

Sachin Nikam

unread,
Dec 9, 2013, 3:50:44 PM12/9/13
to puppet...@googlegroups.com
Jake,
I want to do something like this...
# puppet apply --modulepath=/etc/puppet/modules site.pp "somevalue1" "somevalue2"

is this possible?
Regards
Sachin

Jake Lundberg

unread,
Dec 9, 2013, 4:29:52 PM12/9/13
to puppet...@googlegroups.com
No, not like that.  

You could create your own custom fact and use that via command line.  See: http://www.practicalclouds.com/content/guide/converting-user-data-arguments-facts.   It's not a perfect example, but does have some logic for parsing arguments.

As you're a self proclaimed newbie, this may take longer than you wish.   

Another option is you can wrap creating your manifest (site.pp or imports) in a script, but that's probably not the ideal solution.

What are you trying to do?   Arbitrary remote execution of commands?   If so, Puppet might not be the best platform.   Consider something like Fabric/Capistrano, Ansible or Salt Stack (or just plain Bash).

Sachin Nikam

unread,
Dec 9, 2013, 4:54:00 PM12/9/13
to puppet...@googlegroups.com
Jake,
Thanks for the info. My puppet manifest is doing the same thing as bash script. 
Regards
Sachin

Felix Frank

unread,
Dec 15, 2013, 12:04:38 PM12/15/13
to puppet...@googlegroups.com
Custom facts is a good keyword, and you can get the same effect easier:

FACTER_param1=foo FACTER_param2=bar puppet apply /my/manifest.pp

The "facts" $::param1 and $::param2 will be available to puppet.

Note that it is likely preferable to write an actual bash script instead
of a puppet manifest for this. The whole approach sounds as if you're
using puppet in a way that doesn't cater to its strengths, and hempers
you with some of its weeknesses.

HTH,
Felix
Reply all
Reply to author
Forward
0 new messages