Conditionally replace in file type

62 views
Skip to first unread message

Juan José Presa Rodal

unread,
Jan 23, 2012, 7:10:54 AM1/23/12
to puppet...@googlegroups.com
Hello, I'm making the deployment of an application configuration as follows:

  file {"/home/user/foo/bar":
    ensure  => directory,
    recurse => remote,
    source  => "puppet:///configs/${hostname}/home/user/foo/bar",
    ignore  => ["file1.cfg","file2.cfg"],
  }

I am ignoring these two files ("file1.cfg","file2.cfg"), cause they are dynamically modified by the application. So, not puppet managed.
And here's my problem. Because on the other hand I have to initialize both files in the first run.

What can I do? Is there any way of mix "ignore" and "replace" parameters?
PS: I cannot define other resource with the path of not-managed files, because depending on hostname that path changes.


Thanks in advance and apolgize my poor english!
;) 

krish

unread,
Jan 26, 2012, 4:35:47 PM1/26/12
to puppet...@googlegroups.com
>I am ignoring these two files ("file1.cfg","file2.cfg"), cause they are dynamically modified by the application. So, not puppet managed.
>And here's my problem. Because on the other hand I have to initialize both files in the first run.

first application run?
How would you generally initialize them manually?

Asking to get better idea of the problem.


--
Krish
olindata.com

Daniel Pittman

unread,
Jan 26, 2012, 5:28:21 PM1/26/12
to puppet...@googlegroups.com
On Thu, Jan 26, 2012 at 13:35, krish <das.sri...@gmail.com> wrote:
>>I am ignoring these two files ("file1.cfg","file2.cfg"), cause they are dynamically modified by the application. So, not puppet managed.
>>And here's my problem. Because on the other hand I have to initialize both files in the first run.
>
> first application run?
> How would you generally initialize them manually?

The right answer to these problems is almost always that you have a
`file { ".../foo": ensure => present }` resource in Puppet: that will
put it in place if the file is not present, using whatever source you
give, but will not touch the content of an existing file.

If you are using a recursive file resource to put the rest of the
content in place around this, no problem, because the more specific
file resource will override the recursive one, and you won't
overwrite. :)

--
Daniel Pittman
⎋ Puppet Labs Developer – http://puppetlabs.com
♲ Made with 100 percent post-consumer electrons

Juan José Presa Rodal

unread,
Jan 26, 2012, 5:54:42 PM1/26/12
to puppet...@googlegroups.com
Ok Daniel, thanks for your reply, but I have not control about these individual "noreplace" files because are $hostname dependent.
In different hostnames, have different source locations so I cannot define them in a specific way. 

E.g:

hostname1/home/user/foo/bar/johndoe05/file1.cfg
hostname2/home/user/foo/bar/maryjoe02/file1.cfg


That was the reason for I need something recursive, similar to ignore parameter. (Or a workaround)

Thanks!

Daniel Pittman

unread,
Jan 30, 2012, 8:22:01 PM1/30/12
to puppet...@googlegroups.com
2012/1/26 Juan José Presa Rodal <jua...@gmail.com>:

(I noted that; since this topic was followed up elsewhere I figured to
repeat myself. :)

> Ok Daniel, thanks for your reply, but I have not control about these
> individual "noreplace" files because are $hostname dependent.

Generally, what we would encourage is then that you define them on a
per-hostname basis. You can do that at the node level, or you can
push that down through a define or parameterized class, but the key is
to model that - on a per host basis.

I assume you meant "they are different on every host", rather than
literally being a file with the hostname in it; for that you could
just go with `file { "/path/to/${hostname}.cfg": ... }` to define the
files. :)

> hostname1/home/user/foo/bar/johndoe05/file1.cfg
> hostname2/home/user/foo/bar/maryjoe02/file1.cfg
>
> That was the reason for I need something recursive, similar to ignore
> parameter. (Or a workaround)

Define them per-node. :)

node hostname1 {
# define it in the node
include common::stuff
file { "/home/user/foo/bar/johndoe05/file1.cfg": ... }
# use a parameterized class
class { "something::else": configpath => "/home/user/foo/bar/johndoe05" }
# ...or a define.
some::define { "whatever": configpath => "/home/user/foo/bar/johndoe05" }

Reply all
Reply to author
Forward
0 new messages