How to deploy & excecute script remotely

1,317 views
Skip to first unread message

Raju Patil

unread,
Sep 16, 2013, 2:25:59 AM9/16/13
to puppet...@googlegroups.com
Hi,
 
I am new to Puppet & just had installed Puppet master on Centos.And manging Linux & Windows nodes, now I would like to deploy and execute script on one of my Linux Box Remotely from
Puppet Master.
 
Appriciate your help. Pls. share steps to be followed for achieving above tast.

JuanBrein

unread,
Sep 16, 2013, 8:53:18 AM9/16/13
to puppet...@googlegroups.com
Not hard at all...

just use "file" resource to deploy the file and then "exec" to execute it:

file{ "/path/to/my/script.sh"
  source => "puppet:///modules/${module_name}/script.sh",
  mode => 755,
} ~>

exec { "/path/to/my/script.sh"
   refreshonly => true,
}

The important bit here is the ~> . That means notify and require. It basically means it will notify the exec when the file is deployed and that puppet will push the file before trying to execute it. The refreshonly true will assure you that the script will be executed only if it is notified.

Cheers

Juan

jcbollinger

unread,
Sep 16, 2013, 10:38:10 AM9/16/13
to puppet...@googlegroups.com


It depends on what you mean by that.  If the target node is already registered with the master, and the agent is running on a regular schedule (whether as a standalone service or via a scheduler service such as cron), then you can proceed more or less as JuanBrein described.  There are many variations, nuances, and caveats that he didn't cover, but I'll hold off on those for now, except this one: the approach described will result in the agent running the specified command as part of its next scheduled run.  If instead you want to deploy and run your script right away, then you need something more or different, such as MCollective, for example.


John

Raju Patil

unread,
Sep 19, 2013, 9:01:21 AM9/19/13
to puppet...@googlegroups.com
JuanBrein,
 
Can you pls.mention here, what activites do I have to perform on Master & nodes.
 
Will be very helpful.
 
Since I really dont know where this
 "file" resource to deploy the file and then "exec" to execute it:

 

Raju Patil

unread,
Sep 19, 2013, 9:03:24 AM9/19/13
to puppet...@googlegroups.com

Raju Patil

unread,
Sep 30, 2013, 8:58:16 AM9/30/13
to puppet...@googlegroups.com
I didnt see  "file" resource to deploy the file and then "exec" option on Puppet master. Is there any plugin I have to installed on Master & then these two options will be
visible on Puppet master dashboard. Or I have to do the changes in commandline.
Seriousely, not aware which file to edit & move ahead. Need your help.
 
 

On Thursday, 19 September 2013 18:31:21 UTC+5:30, Raju Patil wrote:

Rob Reynolds

unread,
Sep 30, 2013, 12:01:41 PM9/30/13
to puppet...@googlegroups.com
Raju,
 Being new to puppet, allow me to suggest the Learning Workshop - https://puppetlabs.com/learn.

In conjunection with that, we have a set of free tutorials with a learning VM ( http://docs.puppetlabs.com/learning/ ) that I feel may help alleviate some of these questions.

Give that a shot. Thanks!


--
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 puppet-users...@googlegroups.com.
To post to this group, send email to puppet...@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.



--
Rob Reynolds
Developer, Puppet Labs

Join us at PuppetConf 2014September 23-24 in San Francisco

jcbollinger

unread,
Oct 1, 2013, 9:20:38 AM10/1/13
to puppet...@googlegroups.com


On Monday, September 30, 2013 7:58:16 AM UTC-5, Raju Patil wrote:
I didnt see  "file" resource to deploy the file and then "exec" option on Puppet master. Is there any plugin I have to installed on Master & then these two options will be
visible on Puppet master dashboard. Or I have to do the changes in commandline.
Seriousely, not aware which file to edit & move ahead. Need your help.
 

The File and Exec resource types are built-in to Puppet.  And they are resource types, not classes, which is probably why you are not seeing them in Dashboard.  I strongly recommend that you avoid Dashboard and similar products until you have a reasonable grasp of core Puppet.  You do not need such products to use Puppet, and they will obscure some of the more fundamental details that you need to understand.  You should start with the documentation: http://docs.puppetlabs.com/puppet/3/reference/.  In particular, you should read the Puppet language reference, and you should at least skim the resource type reference in the "Generated References" section.


John

Raju Patil

unread,
Oct 5, 2013, 4:38:55 AM10/5/13
to puppet...@googlegroups.com
I have write the below script in puppet language on puppet master. Now wants to know that, I have to call this script to be excuted from puppet master on End points. How do I do that ?
 
Class users {
  file  { '/opt/example.sh':
     ensure => prsent,
     content => "#!/bin/sh\mkdir /opt/test123\n",
     mode   => '0755',
   }
 exec { "create test123":
    command => '/opt/example.sh',
    creates => '/opt/test123',
    require => File['/opt/example.sh'],
 
 
Do I have to place this script on end point if yes...if I place it on end point how do I call it from Puppet Master
What does this command do
mco exec run script='/opt/example/bin'

jcbollinger

unread,
Oct 7, 2013, 9:45:48 AM10/7/13
to puppet...@googlegroups.com


On Saturday, October 5, 2013 3:38:55 AM UTC-5, Raju Patil wrote:
I have write the below script in puppet language on puppet master. Now wants to know that, I have to call this script to be excuted from puppet master on End points. How do I do that ?


In the strictest sense, you don't do that.  Not at all, ever.  It is very important for you to understand that one computer cannot run anything on another; all it can do is request that the remote computer run something itself.  Even that requires that the remote machine run some kind of program to receive and act on such requests.

In the most common Puppet usage paradigm, manifests such as the one you present reside on the master, and the Puppet agent periodically requests a compiled version (a catalog) from the master, which it (the agent) then 'applies' to its machine.  For this purpose, the agent can run as a local service (daemon) to automate the process on a regular schedule.  Alternatively, it can be run periodically by a scheduler, such as cron, or on demand.

In addition, if the agent is running as a local service, then it can be configured to listen for messages from the master that instruct it to immediately initiate a catalog cycle.  That provides a mechanism by which the master can remotely induce the local machine to retrieve and apply its current catalog. 
 
 
Class users {
  file  { '/opt/example.sh':
     ensure => prsent,
     content => "#!/bin/sh\mkdir /opt/test123\n",
     mode   => '0755',
   }
 exec { "create test123":
    command => '/opt/example.sh',
    creates => '/opt/test123',
    require => File['/opt/example.sh'],
 
 
Do I have to place this script on end point if yes...if I place it on end point how do I call it from Puppet Master


You do not need to place that manifest on the end point.  If you do put it there, however, then you can apply it via a 'puppet apply' command executed on that end point machine (as opposed to 'puppet agent').

 
What does this command do
mco exec run script='/opt/example/bin'
 


The 'mco' command is part of the "Marionette Collective" (MCollective) system for cluster management.  MCollective belongs to PuppetLabs and interoperates with Puppet, but it is not part of Puppet.  Subject to several conditions and provisos, the command requests machines in the cluster to execute the named local command.  This sort of approach can be employed to remotely trigger 'puppet agent' or 'puppet apply' commands, as long as the target machine is configured to support that.


John

Reply all
Reply to author
Forward
0 new messages