2

I am trying to copy files using file resource . My code is as follows:

node 'Node-002' {
 file { "/root/helloworld.txt":
 ensure => file,
 owner  => "root",
 group  => "root",
 mode   => "0644",
 source  => "puppet://modules/templates/${fqdn}/hosts.erb",
}
}

But it is failing with the following error

Error: /Stage[main]/Main/Node[Node-002]/File[/root/helloworld.txt]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/templates/Node-002.example.com/hosts.erb

The template location is as follows:

  ls -l /apps/wps/puppetlabs/code/environments/production/modules/templates/Node-002.example.com/hosts.erb
 -rw-r--r-- 1 puppet puppet 462 Jul 20 02:13 /apps/wps/puppetlabs/code/environments/production/modules/templates/Node-002.wiley.com/hosts.erb

Even if I give the full path in the source parameter , it is failing with the same error.

I am using Puppet 4.5.4

Please suggest

Zama Ques
  • 523
  • 1
  • 9
  • 24

1 Answers1

5

Your module(s) don't appear to conform to the standard directory structure. With a source URL of puppet:///modules/foo/bar.txt, Puppet will be looking for ${codedir}/environments/production/modules/foo/files/bar.txt. Static files should be in a files subdirectory within your module. Templates should be in a templates subdirectory within your module and referenced in a file resource with content => template('foo/bar.erb'). There seems to be some confusion with you using an ERB template as a source which won't get processed in any way.

See https://docs.puppet.com/puppet/latest/reference/modules_fundamentals.html for how your modules should be structured.

bodgit
  • 4,751
  • 16
  • 27
  • Thanks bodgit. It worked . I will remain ever grateful to you. You helped a lot – Zama Ques Jul 21 '16 at 10:35
  • One more query..Instead of putting under modules folder can I copy it under some directory named scripts and put it under ${codedir}/environments/production and access it using source => "puppet://scripts/hosts.sh", – Zama Ques Jul 21 '16 at 12:28
  • 1
    Yes, you can add custom mount points to the Puppet fileserver, see https://docs.puppet.com/puppet/4.5/reference/file_serving.html. – bodgit Jul 21 '16 at 12:49
  • This file is missing . Do i Need to create the file manually at /etc/puppetlabs/puppet/fileserver.conf ? – Zama Ques Jul 21 '16 at 13:01
  • It worked for me. Tried creating /etc/puppetlabs/puppet/fileserver.conf and defined the scripts directory inside it – Zama Ques Jul 21 '16 at 13:25