Jira (PUP-10579) Request: Add "source" and "content" attributes to the exec resource

7 views
Skip to first unread message

Rob Nelson (Jira)

unread,
Jul 6, 2020, 9:41:03 AM7/6/20
to puppe...@googlegroups.com
Rob Nelson created an issue
 
Puppet / New Feature PUP-10579
Request: Add "source" and "content" attributes to the exec resource
Issue Type: New Feature New Feature
Assignee: Unassigned
Created: 2020/07/06 6:40 AM
Labels: feature
Priority: Normal Normal
Reporter: Rob Nelson

As a puppet user
I want the exec resource to support the "source" and "content" attributes
So that I do not need to push a file resource and maintain the link between the two.

 

There is a fairly common use pattern of file -> exec, where you want to exec a fairly complicated action, or even just two commands that need to share some environment that two execs would not share. The file resource pushes down the script. The exec resource runs the script.

file { '/usr/bin/somescript':
  ...
}

exec {'do the thing':
  ensure => present,
  command => '/usr/bin/somescript',
  requires => File['/usr/bin/somescript'],
}

It becomes very easy to create failures when one resource is updated without the other being modified, especially if they are in different classes or separated by some space. A common fault might occur when the script name is changed in the file resource only. The exec will fail on every run because its command does not exist.

The request is for an exec resource that can include the script as part of the resource. There would be no need to put a file in a specific path, the script can either be held in memory or stored in a temporary space on the system. It would look something like:

exec {'do the thing':
  ensure => present,
  source => 'puppet:///modules/profile/do_the_thing.sh',
}

The content attribute could be helpful as well when the command requires some templating.

exec {'do the thing':
  ensure => present,
  content => template('profile/do_the_thing.sh.erb'),
}

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Jerald Sheets (Jira)

unread,
Jul 6, 2020, 10:02:03 AM7/6/20
to puppe...@googlegroups.com
Jerald Sheets commented on New Feature PUP-10579
 
Re: Request: Add "source" and "content" attributes to the exec resource

I think this would be a good thing, but perhaps baking in the same behavior as other resources, where the "command" attribute would support remote items.  So when I would normally use a file resource to place a file in /some/random/path, then execute it with "exec", perhaps baking it into the idiom like so:

 

exec

{ 'thing':   path          => '/foo:/bar:/baz',   command => 'puppet:///modules/foo/do_the_thing.sh', }

 

might be a better route to that end?  Puppet could use vardir or rundir, for example to place the script long enough for execution.  Obviously, this could find itself to be onerous without disciplined use of conditionals like "onlyif" or "unless".

Nate McCurdy (Jira)

unread,
Jul 6, 2020, 11:29:03 AM7/6/20
to puppe...@googlegroups.com
Nate McCurdy commented on New Feature PUP-10579

You can already do something very similar to what you're asking for Rob Nelson by using the shell provider and the file(), epp(), or template() function.

exec { 'hello':
  command  => file('foo/hello_world.sh'),
  onlyif   => file('foo/check.sh'),
  provider => 'shell',
}

A similar example is in the Windows, where the powershell exec provider was designed to handle cases like this: https://forge.puppet.com/puppetlabs/powershell#usage

exec { 'rename-guest':
  command   => file('guest/rename-guest.ps1'),
  onlyif    => file('guest/guest-exists.ps1'),
  provider  => powershell,
  logoutput => true,
}

Rob Nelson (Jira)

unread,
Jul 6, 2020, 5:31:04 PM7/6/20
to puppe...@googlegroups.com
Rob Nelson commented on New Feature PUP-10579

That's neat. That should definitely be highlighted in the type references.

One issue I see is that this doesn't necessarily leave the file where it can be observed. Especially if it's a template, if there are issues running it it would be nice to see it on disk (or otherwise obtain its contents) for troubleshooting whether it's a template generation or a command running issue.

Reply all
Reply to author
Forward
0 new messages