Executing bash script from puppet fails

夙愿已清 提交于 2019-12-24 07:06:09

问题


I have been trying to copy and execute a shell script residing in puppet master machine to my puppet agent

This is my code

[root@ip-****** manifests]# cat site.pp
class mymodule::myklass{
  file {'my_bash_script':
      ensure => 'file',
      source => '/etc/puppet/modules/mymodule/my_bash_script.sh',
      path   => '/home/ec2-user/my_bash_script.sh',
      owner  => 'root',
      mode   => '755',
      notify => Exec['run_my_script'],
  }
  exec { 'run_my_script':
    command => '/home/ec2-user/my_bash_script.sh',
  }
}
include mymodule::myklass

my script:

[root@ip-********* mymodule]# cat my_bash_script.sh
#!/bin/sh
mv /usr/bin/node /usr/bin/bnode
ln -s /usr/local/bin/node /usr/bin/node
mv /usr/bin/npm /usr/bin/bnpm
ln -s /usr/local/bin/npm /usr/bin/npm

I am getting the following error:

[root@ip-*********** /]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ip*****************8
Info: Applying configuration version '1472235841'
Error: /Stage[main]/Mymodule::Myklass/File[my_bash_script]: Could not evaluate: Could not retrieve information from environment production source(s) puppet:///modules/mymodule/my_bash_script.sh
Notice: /Stage[main]/Mymodule::Myklass/Exec[run_my_script]: Dependency File[my_bash_script] has failures: true
Warning: /Stage[main]/Mymodule::Myklass/Exec[run_my_script]: Skipping because of failed dependencies
Notice: Finished catalog run in 0.08 seconds

Can anyone please help me resolve this error?


回答1:


You have to use the puppet module URI to source your file resources if they are located in your module/files directories:

file {'my_bash_script':
  ensure => 'file',
  source => 'puppet:///modules/mymodule/my_bash_script.sh',
  path   => '/home/ec2-user/my_bash_script.sh',
  owner  => 'root',
  mode   => '755',
  notify => Exec['run_my_script'],
}

Note the documentation here: https://docs.puppet.com/puppet/latest/reference/types/file.html#file-attribute-source

If it still fails with that error, then that means the file is missing from your $modulepath/mymodule/files/my_bash_script.sh so you need to place it there.

Furthermore, your bash script could be converted to intrinsic Puppet DSL, and it is odd that you are including a class inside of itself at the end.



来源:https://stackoverflow.com/questions/39172759/executing-bash-script-from-puppet-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!