Conditionally install a file resource

29 views
Skip to first unread message

John Florian

unread,
May 4, 2009, 4:58:53 PM5/4/09
to Puppet Users
I keep finding that I wish onlyif was a meta-parameter; right now I
want it on the file resource type.

I need to install a file, but only if the source exists. It's a
really simple file resource that works great when the source exists,
but fails when it doesn't. I don't care if it fails, but I do not
want it to terminate the whole dependency chain. Here's what I'm
working with:

define network($interface_name) {

file { "ifcfg-$interface_name":
group => root,
mode => 644,
owner => root,
path => "/etc/sysconfig/network-scripts/ifcfg-
$interface_name",
source => [ "$puppeteer_cache/ifcfg-$interface_name" ],
}

service { "network":
enable => true,
ensure => running,
hasrestart => true,
status => "test -e /var/lock/subsys/network",
subscribe => [
File["ifcfg-$interface_name"],
],
}

}

The contents of the $puppeteer_cache directory are independently
populated by rsync and are based upon the system's MAC address. So
puppet doesn't know if the the file source is there or not.

Just to be clear, another resource depends on Service["network"] and I
want it run regardless of whether a "$puppeteer_cache/ifcfg-
$interface_name" file exists or not. Most of the systems this runs on
are using DHCP, which will work fine given the default content of this
file. I only want to deploy this file this way for those systems that
need a static address.

Do I have to kludge this with an exec type or is there some way to use
the file type that I'm missing?

Robin Sheat

unread,
May 4, 2009, 9:57:38 PM5/4/09
to puppet...@googlegroups.com
On Tuesday 05 May 2009 08:58:53 John Florian wrote:
> I keep finding that I wish onlyif was a meta-parameter; right now I
> want it on the file resource type.

I think this would be good, too. I encountered exactly the same situation
yesterday.

--
Robin <ro...@kallisti.net.nz> JabberID: <eyt...@jabber.kallisti.net.nz>
http://www.kallisti.net.nz/blog ||| http://identi.ca/eythian

PGP Key 0xA99CEB6D = 5957 6D23 8B16 EFAB FEF8 7175 14D3 6485 A99C EB6D

signature.asc

Trevor Vaughan

unread,
May 5, 2009, 10:20:53 AM5/5/09
to puppet...@googlegroups.com
I agree that this would be useful, and fairly easy to add.

I believe that the current best practice for this is to use a custom fact.

If you stick it into the Puppet bug tracker as a feature request
someone in the community may bite, or at least the technical merits
can be hammered out.

Trevor

James Turnbull

unread,
May 5, 2009, 10:24:54 AM5/5/09
to puppet...@googlegroups.com
Trevor Vaughan wrote:
> I agree that this would be useful, and fairly easy to add.
>
> I believe that the current best practice for this is to use a custom fact.
>
> If you stick it into the Puppet bug tracker as a feature request
> someone in the community may bite, or at least the technical merits
> can be hammered out.
>

http://projects.reductivelabs.com/issues/651

Regards

James Turnbull

--
Author of:
* Pro Linux Systems Administration
(http://www.amazon.com/gp/product/1430219122/)
* Pulling Strings with Puppet
(http://www.amazon.com/gp/product/1590599780/)
* Pro Nagios 2.0
(http://www.amazon.com/gp/product/1590596099/)
* Hardening Linux
(http://www.amazon.com/gp/product/1590594444/)

signature.asc

Robin Sheat

unread,
May 5, 2009, 9:41:06 PM5/5/09
to puppet...@googlegroups.com
On Wed, 06 May 2009, James Turnbull wrote:
> http://projects.reductivelabs.com/issues/651

Internal error

An error occurred on the page you were trying to access.
If you continue to experience problems please contact your redMine
administrator for assistance.

...I saw this error yesterday when looking for something, too. Is it a
constant problem, or just my bad timing?

Hostes alienigeni me abduxerunt. Qui annus est?

signature.asc
Reply all
Reply to author
Forward
0 new messages