问题描述:

I've got a puppet class defined like this:

class etchostfile

(

$hostfile

)

file { $hostfile :

ensure => file,

source => "file:///var/www/cobbler/pub/hosts-${hostfile}.txt",

path => '/root/hosts',

}

}

Then I've got a node defined:

node 'hostname.fqdn.com'

{

class { 'etchostfile' :

hostfile => foo,

}

}

I want it to take the file /var/www/cobbler/pub/hosts-foo.txt and install it to /root/hosts. But I'm getting this error:

err: /Stage[main]/Etchostfile/File[foo]: Could not evaluate: Could not

retrieve information from environment production source(s)

file:///var/www/cobbler/pub/hosts-foo.txt

The file exists, is readable, and every directory leading to it is at least r-x.

I saw a number of reasons why this error applies to an incorrect puppet:/// source, but I'm using a file:/// source. I also tried disabling SELinux on both agent and master. No luck.

It worked correctly on my test host, so I presume it's a firewall issue. But the agent can get to the master on port 8140, and I already have a signed certificate, and it appears that I am at least getting a catalog, so I don't understand why I can't get a file too.

网友答案:

Looks like you are trying to source the file from your puppet master? In that case, you need to use the puppet:// resource and not the file:// resource.

Also, ensure that your fileserver setup on master is working.

https://docs.puppetlabs.com/guides/file_serving.html#file-server-configuration

[EDIT] From the above linked doc first paragraph:

If a file resource declaration contains a puppet: URI in its source attribute, nodes will retrieve that file from the master’s file server

Also, some more doc talking about file source attribute https://docs.puppetlabs.com/references/latest/type.html#file-attribute-source

网友答案:

If you are trying to reference a local file (local to the node where the agent is running) you can remove the protocol part and just use:

file { $hostfile :
    ensure => file,
    source => "/var/www/cobbler/pub/hosts-${hostfile}.txt",
    path   => '/root/hosts',
}

If you are trying to access a file on the puppet master, you need to use the puppet:/// protocol (and not file). This will bring some additional restrictions : usually you do not configure puppet file serving to serve all files on the master (which would be a security issue) but only to serve files that are part of puppet modules.

Or you could use a template with no logic instead of the file:

file { $hostfile :
    ensure  => file,
    content => template("my_module/hosts-${hostfile}.txt.erb"),
    path    => '/root/hosts',
}

It is counter intuitive, but using templates with no logic tends to have better performance that trying to use Puppet for file serving.

相关阅读:
Top