从木偶执行 bash 脚本失败 [英] Executing bash script from puppet fails

查看:52
本文介绍了从木偶执行 bash 脚本失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试将驻留在 puppet master 机器中的 shell 脚本复制并执行到我的 puppet 代理

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

这是我的代码

[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

我的脚本:

[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

我收到以下错误:

[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?

推荐答案

你必须使用 puppet 模块 URI 来获取你的 file 资源,如果它们位于你的 module/files 目录:

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'],
}

请注意此处的文档:https://docs.puppet.com/puppet/latest/reference/types/file.html#file-attribute-source

如果它仍然失败并出现该错误,则意味着您的 $modulepath/mymodule/files/my_bash_script.sh 中缺少该文件,因此您需要将其放在那里.

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.

此外,您的 bash 脚本可以转换为内在的 Puppet DSL,而且奇怪的是您最后在其自身内部包含了一个类.

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.

这篇关于从木偶执行 bash 脚本失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆