在puppet上运行python脚本

时间:2016-04-14 17:15:14

标签: python ubuntu server puppet puppet-enterprise

我是新手使用puppet,并设置了主服务器和代理服务器。我很难弄清楚如何在代理服务器上运行python脚本。

我已按照快速入门指南进行了搜索,但我无法找到明确的解释。

目前,我的site.pp有:

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

pythontest的manifest文件夹中的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']
    }
}

两者都在运行Ubuntu 15.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路径名,但是一些谷歌搜索会找到一些使用该方法的人。

2 个答案:

答案 0 :(得分:1)

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

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中使用Puppet。

答案 1 :(得分:-1)

想出来了!

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

我错过了/之前/等。进行了更改,前两个文件命令创建一个目录,然后使用source =>复制文件本身。木偶:///

最后,exec要求我找到在puppet代理上安装python的地方并将其用作命令,因此使用/ usr / bin / python。

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

添加logoutput =>是的,给了我期待的输出。