Shorten require list

39 views
Skip to first unread message

ge...@timble.net

unread,
Mar 12, 2013, 6:45:57 AM3/12/13
to puppet...@googlegroups.com
Hi,

I have an Exec which requires a lot of packages (15-20):

Exec { 'name':
  ...
  require => [ Package['first'], Package['second'], Package['third'], ... ]
}

Is there a way to shorten this list and make it easier to read?

Gergo Erdosi

Matthew Burgess

unread,
Mar 12, 2013, 6:52:05 AM3/12/13
to puppet...@googlegroups.com
15-20 packages for one exec statement? That seems excessive. What
does that exec statement look like, at the moment, the only way I can
imagine an exec statement requiring that number of packages is by it
being a pipeline of 15 commands, each of which comes from a separate
package.

Ta,

Matt.

R.I.Pienaar

unread,
Mar 12, 2013, 6:57:41 AM3/12/13
to puppet...@googlegroups.com
if the packages are in a class, just require Class["foo"].

If the packages are tagged by some shared name 'foo':

Package<| tag == "foo" |> -> Exec["name"]

ge...@timble.net

unread,
Mar 12, 2013, 6:59:15 AM3/12/13
to puppet...@googlegroups.com
Hi Matt,

It installs PHP from source. The required packages are mostly libraries (libxml2-dev, libpcre3-dev, etc). Here is the file if it helps to better understand my problem:

The exec is on line 175.

Gergo Erdosi

ge...@timble.net

unread,
Mar 12, 2013, 7:04:53 AM3/12/13
to puppet...@googlegroups.com
Hi,

Thanks, I will look into tags, it could be solution indeed. I also thought about moving those packages into a separate class (eg. packages.pp), was just wondering what my options are if I leave them in install.pp.

Gergo Erdosi

R.I.Pienaar

unread,
Mar 12, 2013, 7:10:43 AM3/12/13
to puppet...@googlegroups.com


----- Original Message -----
> From: ge...@timble.net
> To: puppet...@googlegroups.com
> Sent: Tuesday, March 12, 2013 11:04:53 AM
> Subject: Re: [Puppet Users] Shorten require list
>
> Hi,
>
> Thanks, I will look into tags, it could be solution indeed. I also thought
> about moving those packages into a separate class (eg. packages.pp), was
> just wondering what my options are if I leave them in install.pp.

Really though it sounds like you're to reinvent packaging by running a few
execs and discovering that - unsurprisingly - it's not that simple.

You should make a package and use that instead of compiling php on demand.

Use fpm, it makes it as easy as using tar.

ge...@timble.net

unread,
Mar 12, 2013, 7:16:39 AM3/12/13
to puppet...@googlegroups.com
I know, this is not the first time I hear packages are the preferred way, and I completely agree. We will look into packaging later, but for now we needed to get the script to work. This is the first version, I already have ideas how to improve it.

Gergo Erdosi

David Schmitt

unread,
Mar 12, 2013, 7:19:09 AM3/12/13
to puppet...@googlegroups.com
You can use

require => Package['first', 'second', 'third', ...]

instead.

Also, putting this into a variable and using that instead, may improve
your situation:

$packages = ['first', 'second', 'third', ...]

package { $packages: ensure installed }

exec { "foo": require => Package[$packages] }

Best Regards, David

Gergo Erdosi

unread,
Mar 12, 2013, 7:24:24 AM3/12/13
to puppet...@googlegroups.com
Hi David,

Nice, didn't know I can use multiple packages inside Package. Thanks!

Gergo Erdosi
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Puppet Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/puppet-users/LYxmrugXGps/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, 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?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Fabrice Bacchella

unread,
Mar 12, 2013, 8:27:34 AM3/12/13
to puppet...@googlegroups.com

Le 12 mars 2013 à 12:24, Gergo Erdosi <ge...@timble.net> a écrit :

> Hi David,
>
> Nice, didn't know I can use multiple packages inside Package. Thanks!
>
> Gergo Erdosi
>
> On Tue, Mar 12, 2013 at 12:19 PM, David Schmitt <da...@dasz.at> wrote:
>> On 12.03.2013 11:45, ge...@timble.net wrote:
>>>
>>> Hi,
>>>
>>> I have an Exec which requires a lot of packages (15-20):
>>>
>>> Exec { 'name':
>>> ...
>>> require => [ Package['first'], Package['second'], Package['third'], ...
>>> ]
>>> }
>>>
>>> Is there a way to shorten this list and make it easier to read?
>>
>>
>> You can use
>>
>> require => Package['first', 'second', 'third', ...]
>>
>> instead.
>>
>> Also, putting this into a variable and using that instead, may improve your
>> situation:
>>
>> $packages = ['first', 'second', 'third', ...]
>>
>> package { $packages: ensure installed }
>>
>> exec { "foo": require => Package[$packages] }
>>
>> Best Regards, David


This works too :

package{'needed for exec':
name => $packages,
ensure => present,
}

exec { "foo": require => Package['needed for exec'] }

Less object, so a smaller catalog, and faster because your package tool is run once, not one time for each package.

jcbollinger

unread,
Mar 12, 2013, 12:46:46 PM3/12/13
to puppet...@googlegroups.com

This works too :

package{'needed for exec':
  name => $packages,
  ensure => present,
}

exec { "foo": require => Package['needed for exec'] }

Less object, so a smaller catalog, and faster because your package tool is run once, not one time for each package.


I have trouble believing that that works completely, and if it does, I would be amazed to find that it avoids running the package tool separately for each package.

Ways I imagine it might fail include:
  • Puppet attempts to manage a single package whose name is a concatenation of the names in $packages ("firstsecondthird...")
  • Puppet manages only the first package listed in $packages, ignoring the others
  • Puppet does not correctly detect when the packages are already installed, and therefore attempts to install them on every run
If it does none of those things then I have great difficulty believing that it does not create a separate Package resource for each element of $packages, and therefore indeed run the package manager once for each.

And if it in fact behaves exactly as promised, then that constitutes undocumented behavior, and it is therefore unsafe to rely upon.

So don't do that.


John

Fabrice Bacchella

unread,
Mar 12, 2013, 4:26:26 PM3/12/13
to puppet...@googlegroups.com
Le 12 mars 2013 à 17:46, jcbollinger <John.Bo...@stJude.org> a écrit :


This works too :

package{'needed for exec':
  name => $packages,
  ensure => present,
}

exec { "foo": require => Package['needed for exec'] }

Less object, so a smaller catalog, and faster because your package tool is run once, not one time for each package.


I have trouble believing that that works completely, and if it does, I would be amazed to find that it avoids running the package tool separately for each package.

Ways I imagine it might fail include:
  • Puppet attempts to manage a single package whose name is a concatenation of the names in $packages ("firstsecondthird...")
  • Puppet manages only the first package listed in $packages, ignoring the others
  • Puppet does not correctly detect when the packages are already installed, and therefore attempts to install them on every run
If it does none of those things then I have great difficulty believing that it does not create a separate Package resource for each element of $packages, and therefore indeed run the package manager once for each.

It does nothing of that, I use it a lot in my modules and it solves many problems. I didn't test it on many platform, but it works quite well on rpm-based providers.


And if it in fact behaves exactly as promised, then that constitutes undocumented behavior, and it is therefore unsafe to rely upon.

It not so undocumented. You don't just convert a array to a string, you get an empty separator ['a', 'b'] is converted to 'ab', for what I saw in many of my mistakes. So someone was thinking about my use case and add the code to have a ' ' separator for the rpm command.

jcbollinger

unread,
Mar 13, 2013, 9:17:10 AM3/13/13
to puppet...@googlegroups.com


On Tuesday, March 12, 2013 3:26:26 PM UTC-5, Fabrice Bacchella wrote:

It not so undocumented.

Point me to the docs, then.


John

Reply all
Reply to author
Forward
0 new messages