On Friday, September 20, 2013 10:10:13 PM UTC-5, François Lafont wrote:
>
> Just one precision...
>
> Le 21/09/2013 04:27, François Lafont wrote :
>
> > Is it possible with Puppet to copy the file:
> >
> > /a/path/foo # <-- in node-source
> >
> > from "node-source" to "node-destination", but with a different path.
The "different path" bit is not really a differentiator here. The issue is
the same whether the local and remote paths are the same or different.
> By example:
> >
> > /another/path/bar # <-- in node-destination
> >
> > I know it's possible with exported files when the path is the same in
> node-source and node-destination but here the paths are different.
>
>
No, it's not possible with exported File resources.
> I thought this code could work:
>
> For node-source
>
> @@file {'/another/path/bar':
> path => "/another/path/bar",
> source => "/a/path/foo",
> tag => "exported",
> #...
> }
>
> and for node-destination
>
> File <<| tag == "exported" |>>
>
> but it doesn't work because [source => "/a/path/foo"] uses the
> "/a/path/foo" file of node-destination (if exists), not the /a/path/foo
> file of note-source.
>
Yes. "Exported resources" are more precisely described as exported
resource *declarations*. They do not capture any actual resource. Under
some circumstances, an exported resource might still be a viable tool for
this task, but not the particular one you tried to use.
There is a fundamental design question that you must settle straight off:
do you intend that the destination node(s) obtain the fail directly from
the source node (in which case you will need to use an Exec resource), or
indirectly via the master (in which case you will use a File)?
Next, you must consider whether the destination node needs any information
that can only be obtained (semi-)dynamically from the source node. For
instance, will the file's source path vary depending on the source node's
facts? Is the imperative for the target node to have a copy of the file at
all dependent on the source node? These questions will help you determine
whether you need an exported resource or whether an ordinary one would be
sufficient. Only if the resource parameters or the simple existence of a
declaration at all depend in some way on the source node's facts do you
need an exported resource. Under all other circumstances an ordinary
resource is viable and preferable.
Third, you should be mindful that Puppet is a state management service, not
a script engine. As such, it is much to your advantage to frame your
objective in terms of the state you want Puppet to achieve and maintain:
that the destination file is a duplicate of the source file. In
particular, it is to your advantage to avoid doing any unnecessary
copying. You will get that for free if you can use a File resource, but
you may need to work for it if you have to use an Exec. Getting this right
can have broader impact than just the efficiency of your Puppet runs.
There are two many variables here for me to give you a specific solution
that I am confident will fit your needs, but here's an example. I suppose
that your list of source nodes is difficult or impossible for the master to
determine directly, so that exported resources are appropriate; that it is
desirable for the master to mediate the file exchange, so that the type of
the exported resource will be File; and that the content of each of the
files involved is small. In that case, you could do this:
- Create a custom fact 'foo_content' with which nodes will report the
contents of /a/path/foo to the master
- Have the relevant source nodes export appropriate file resources, like
so:
@@file { "/another/path/${::hostname}":
ensure => file,
content => ${::foo_content},
tag => 'foo_files',
# other parameters as appropriate
}
- Have the destination node(s) import the results.
That's pretty close to what you were trying; most of the other alternatives
diverge more.
John
--
You received this message because you are subscribed to the Google Groups
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.