kckaiwei kckaiwei - 1 year ago 431
Python Question

Running a python script on puppet

I'm new to using puppet, and have a master and agent server set up. I'm having difficulty figuring out how to run a python script on the agent server.

I've followed the quick start guide and have been searching for an answer, but I can't find a clear explanation.

Currently, my site.pp has:

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

the init.pp in pythontest's manifest folder has:

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

Both are running Ubuntu 15.04

So far, Hello world is displayed, and the python module gets installed (https://forge.puppet.com/stankevich/python).

I get the error:

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

I think I can't just put exec : python pathname, but some google searches finds some people using that method.

Answer Source

Better still to specify your dependencies:

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

Also unclear why you're trying to manage Puppet's own files (in /etc/puppetlabs/code with Puppet.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download