puppet execute remote script on all servers

7,657

Solution 1

The error:

Failed to retrieve current state of resource: Could not retrieve information from source(s)

means that puppet could not retrieve the file from the puppetmaster. The second error is because it won't attempt to execute the file if it can't retrieve the file.

I think you'll find this page useful as you learn puppet: http://bitcube.co.uk/content/puppet-errors-explained The error you are hitting here is the top one on that page. It also has some more information about where puppet expects files to be. The URLs don't necessarily match up directly with the file system paths.

In general, when debugging error messages, fix the first one first. It's quite common for later error messages to be caused by earlier ones.

Solution 2

You should use the recommended directory structure, something like this:

|-- environments
|   |-- development
|   |   `-- modules
|   `-- testing
|       `-- modules
|-- manifests
|   |-- defines
|   |   `-- netinstall.pp
|   |-- nodes.pp
|   `-- site.pp
|-- modules
|   |-- python
|   |   |-- files
|   |   |-- manifests
|   |   `-- templates

put your class into modules/python/manifests, the curp.py into modules/python/files, and use source like belows:

source => 'puppet:///modules/python/curp.py',
Share:
7,657
krisdigitx
Author by

krisdigitx

Updated on September 18, 2022

Comments

  • krisdigitx
    krisdigitx over 1 year

    how can i execute a python script on all puppet clients.

    i have added a class for the script to be executed

    class curp {
           exec { "/usr/src/scripts/curp.py": }
    }
    

    and included it in nodes.pp

    but when i execute on the remote client, it says file cannot be found ???

    #client:# /usr/sbin/puppetd --test --server=puppetmasterserver
    notice: //chkconfig/Package[vsftpd]/ensure: created
    err: //curp/Exec[/usr/src/scripts/curp.py]/returns: change from notrun to 0 failed: Could not `find executable /usr/src/scripts/curp.py`
    

    more edition:

    i have fixed the configissue by creating a fileserver,

    class curp {
           file { '/opt/files/curp.py':
              ensure => present,
              owner => 'root',
              group => 'root',
              mode => '0755',
              source => 'puppet:///modules/files/curp.py',
           }
           exec { '/opt/files/curp.py': require => File['/opt/files/curp.py'] }
    

    }

    but the script fails with a dependency, i cant find anywhere else in the log to what it is related to...

    err: //curp/File[/opt/files/curp.py]: Failed to retrieve current state of resource: Could not retrieve information from source(s) puppet:///modules/files/curp.py at /etc/puppet/manifests/templates.pp:114
    notice: //curp/Exec[/opt/files/curp.py]: Dependency file[/opt/files/curp.py] has 1 failures
    warning: //curp/Exec[/opt/files/curp.py]: Skipping because of failed dependencies
    

    Any ideas?

    resolved:

    problem was /opt/files did not exist on the client servers, it works when the remote directory is available

    • womble
      womble over 12 years
      So what does ls -l /usr/src/scripts/curp.py say?
    • pfo
      pfo over 12 years
      This is actually what mcollective is for.
    • Razique
      Razique over 12 years
      You have forget the coma after two lines : source => "puppet:///modules/curp/curp.py" }, exec { "/usr/src/scripts/curp.py": },
    • Greg Petersen
      Greg Petersen over 12 years
      source => 'puppet:///puppet/files/curp.py', --> what does your puppet directory structure look like?
    • krisdigitx
      krisdigitx over 12 years
      the curp.py file is located in /etc/puppet/modules/files/curp.py
  • womble
    womble over 12 years
    You don't need a file statement if the script's already on the system, and you really don't need an explicit require, because Puppet will autorequire if needed.
  • Razique
    Razique over 12 years
    Good to know, thanks. I've always thought that I should use the "require", so I make sure that the function is being run without error.
  • krisdigitx
    krisdigitx over 12 years
    the curp.py file is located in /etc/puppet/modules/files/curp.py
  • Ladadadada
    Ladadadada over 12 years
    The URL you have in your error message: puppet:///modules/files/curp.py will be trying to find the file in /etc/puppet/modules/modules/files/files/curp.py on the puppetmaster. If the file is in a module called "curp" the URL you want is puppet:///curp/curp.py