Re: [Puppet Users] exec executes remote command but the actual script not run

371 views
Skip to first unread message

Peter Bukowinski

unread,
Aug 8, 2012, 12:29:06 PM8/8/12
to puppet...@googlegroups.com
On Aug 8, 2012, at 5:40 AM, duckegg01 wrote:

> Hi
>
> I have wriiten a class to deploy a tra file and extract on a remote puppet client. The tar file gets copied across fine and it seems to puppet the thet tar extraction suceeds, but when I check the client I dont see the extracted files
>
> exec { "Deploy Code":
> command => "/bin/tar -xvf /var/tmp/deploy.tar",
> onlyif => [
> "/usr/bin/test -d /var/tmp/test/" #just testing this
> ]
> }

I see two possible issues. First, you either need to give the exec resource a working directory via the 'cwd' parameter, or you need to use tar's -C option to specify where to extract the files. Without either of these, files will extract into the home of whichever user is running puppet. So either add this parameter:

cwd => '/var/tmp/,

or use this as your tar command ( -- # note that I skipped the verbose switch since it's not interactive):

/bin/tar -xf /var/tmp/deploy.tar -C /var/tmp

Another possible issue: If you want /var/tmp/deploy.tar to extract to /var/tmp/test, then you need to leave off the 'onlyif' parameter. Currently, the exec will only run if /var/tmp/test already exists.

One last thing. If you haven't done so already, set up a dependency between the file resource that copies the tar file to the node and the exec resource that extracts it -- either via a notify parameter in the file resource or a require parameter in the exec resource.

--
Peter Bukowinski

duckegg01

unread,
Aug 9, 2012, 4:51:27 AM8/9/12
to puppet...@googlegroups.com
Hi Peter

I managed to get this working by have the cwd in place, but im interested in your point with regards to setting up the dependency any chance you can provide an example of this based on what I have at present.

Peter Bukowinski

unread,
Aug 9, 2012, 8:24:23 AM8/9/12
to puppet...@googlegroups.com
Adding this parameter to your file resource,

    notify => Exec['Deploy Code'],

and these parameters to your exec resource,

    require    => File['/var/tmp/deploy.tar'],
    refreshonly => true,

will create the appropriate dependency.  Basically, it makes sure the file resource must run before the exec. Puppet manifests do not run in a top down manner, do it's important to specify the order of resouces when necessary.

--
Peter
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/gOIxni7fKGIJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

jcbollinger

unread,
Aug 10, 2012, 9:04:51 AM8/10/12
to puppet...@googlegroups.com


On Thursday, August 9, 2012 7:24:23 AM UTC-5, pmbuko wrote:
Adding this parameter to your file resource,

    notify => Exec['Deploy Code'],

and these parameters to your exec resource,

    require    => File['/var/tmp/deploy.tar'],
    refreshonly => true,

will create the appropriate dependency.  Basically, it makes sure the file resource must run before the exec. Puppet manifests do not run in a top down manner, do it's important to specify the order of resouces when necessary.

Technically, either the 'notify' on one side or the 'require' on the other is sufficient to create a relationship, and 'refreshonly' is a tangential issue.  I prefer to avoid specifying relationships redundantly, as it complicates maintenance.  The Exec's relationship to the File is a true dependency, so I would express the relationship on that side.

Inasmuch as it makes sense to deploy the code only when the tarball changes, 'refreshonly' is a good choice.  In that case, I would use:

In the File:
# nothing special

In the Exec:
refreshonly => true,
listen => File['/var/tmp/deploy.tar']

Note also that if you're going to use this means to deploy code then you should probably put the tarball in a permanent location and plan on leaving it there.  If you delete it after the deployment then Puppet will copy it back down (and trigger a new deployment) on its next run.


John

Peter Bukowinski

unread,
Aug 10, 2012, 11:23:16 AM8/10/12
to puppet...@googlegroups.com
The listen parameter is new to me. Good to know!

--
Peter

jcbollinger

unread,
Aug 10, 2012, 4:13:39 PM8/10/12
to puppet...@googlegroups.com


It's new to me, too: I meant to say "subscribe".  Sorry about that.


John

Reply all
Reply to author
Forward
0 new messages