运行 人偶上的 python 脚本

Running a python script on puppet

我刚开始使用 Puppet,并且设置了主服务器和代理服务器。我很难弄清楚如何在代理服务器上 运行 python 脚本。

我已经按照快速入门指南寻找答案,但找不到明确的解释。

目前,我的 site.pp 有:

node default {
    class { 'helloworld':}
    class { 'helloworld::motd':}
    include python
    class { 'pythontest':}
}

pythontest 的清单文件夹中的 init.pp 有:

class pythontest {
    exec {'python etc/puppetlabs/code/environments/production/modules/pythontest/print.py':
    require => File['etc/puppetlabs/code/environments/production/modules/pythontest/print.py']
    }
}

两者都是运行宁Ubuntu15.04

至此,显示了 Hello world,并安装了 python 模块 (https://forge.puppet.com/stankevich/python)。

我收到错误:

Error: Failed to apply catalog: Validation of Exec[etc/puppetlabs/code/environments/production/modules/pythontest/print.py] failed: 'etc/puppetlabs/code/environments/production/modules/pythontest/print.py' is not qualified and no path was specified. Please qualify the command or specify a path. at etc/puppetlabs/code/environments/production/pythontest/manifests/init.pp:2

我想我不能只输入 exec : python 路径名,但是一些 google 搜索发现一些人使用该方法。

想通了!

class pythontest {
    file { '/etc/puppetlabs/code/environments/production/modules/pythontest/':
    ensure => directory,
    mode => '0755',
    }
    file { '/etc/puppetlabs/code/environments/production/modules/pythontest/print.py":
    mode => '0644',
    source => 'puppet:///modules/pythontest/print.py',
    }
    exec { 'pythontestprint':
    path => '/usr/bin',
    logoutput => true,
    command => '/usr/bin/python /etc/puppetlabs/code/environments/production/modules/pythontest/print.py',
    }
}

我在 /etc 之前错过了 /。进行了更改,第一个两个文件命令创建一个目录,然后使用 source => puppet:///

复制文件本身

最后,执行官要求我找到 python 在 puppet 代理上的安装位置,并将其用作命令,因此 /usr/bin/python。

给我一个通知:/Stage[main]/Pythontest/Exec[pythontestprint]/returns:执行成功。

添加一个 logoutput => true,得到我期望的输出。

最好还是指定您的依赖项:

class pythontest {
  file { '/etc/puppetlabs/code/environments/production/modules/pythontest/':
    ensure => directory,
    mode => '0755',
  }
  file { '/etc/puppetlabs/code/environments/production/modules/pythontest/print.py':
    mode => '0644',
    source => 'puppet:///modules/pythontest/print.py',
  }
  exec { 'pythontestprint':
    path => '/usr/bin',
    command => '/usr/bin/python /etc/puppetlabs/code/environments/production/modules/pythontest/print.py',
    require => File['/etc/puppetlabs/code/environments/production/modules/pythontest/print.py'],
  }
}

还不清楚您为什么要尝试管理 Puppet 自己的文件(在 /etc/puppetlabs/code with Puppet 中。