I have seen the similar post here, but that does not solve
Intent is to copy the bash script on agent node and execute.
SLES11SP4-118:~ # cat /etc/puppet/manifests/site.pp
node default {
include base
}
node 'sles11sp4-170.dev.insiteone.com' {
class {'base':}
}
class base {
exec { "remove yum":
command => 'zypper removerepo 1',
logoutput => 'true',
path => '/usr/bin/'
}
exec { "add yum":
command => 'zypper addrepo -f http://10.156.14.121/repo/RPMS/QA/ QA',
logoutput => 'true',
path => '/usr/bin/'
}
file {
'my_expect_script':
ensure => 'present',
source => "puppet:///modules/raj/myexpect.sh",
path => '/tmp/',
owner => 'root',
group => 'root',
mode => '0744',
notify => Exec['run_my_script'],
}
exec {
'run_my_script':
command => '/tmp/myexpect.sh',
refreshonly => true,
}
}
In /etc/puppet.conf
SLES11SP4-118:~ # vim /etc/puppet/puppet.conf
[main]
dns_alt_names=puppet,puppet.dev.insiteone.com
server=puppet.dev.insiteone.com
modulepath=/etc/puppet/modules
I have made sure the directories are present in puppet server :
SLES11SP4-118:~ # puppet config print modulepath
/etc/puppet/modules:/usr/share/puppet/modules
SLES11SP4-118:~ # ls /etc/puppet/modules/raj/
myexpect.sh
SLES11SP4-118:~ # ls /usr/share/puppet/modules/raj/
myexpect.sh
Error (puppet apply /etc/puppet/manifests/site.pp –debug):
err: /Stage[main]/Base/File[my_expect_script]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/raj/myexpect.sh at /etc/puppet/manifests/site.pp:31
notice: /Stage[main]/Base/Exec[run_my_script]: Dependency File[my_expect_script] has failures: true
warning: /Stage[main]/Base/Exec[run_my_script]: Skipping because of failed dependencies
The first two execs works fine though (remove yum and add yum)
Best Answer
Thanks to Tim Stoop (who pointed it out in comment). So whenever you add a file in some location and add the source, you need to put them inside the "files" directory, and more importantly the files directory should not be named in the sources.
Like my source is:
source => "puppet:///modules/raj/myexpect.sh"
so the actual file needs to be in/etc/puppet/modules/raj/files
This is mentioned in the puppet doc: https://docs.puppet.com/puppet/4.9/modules_fundamentals.html#files
(I had missed it completely until @Tim Stoop pointed above in the comments.
Next is, the path in the
files
module was incorrect. You need to put the entire path including the filename there. Usingensure => 'present'
the puppet makes sure the file is present there, if not it creates it.Hence: path =>
/tmp/myexpect.sh
is correct.The entire correct manifest is below: