Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have installed puppetmaster in ubuntu 11.04 and i have installed puppet in all my clients. I have joined all my puppet clients with puppet master. Is it possible to copy a file to all these puppet clients from puppet master?

For example:

I have the file named datas.xls in my Desktop (Puppet Master). How do i copy this files to all my puppet clients in the following location ( /home/operator1/Desktop/Backup/) ?

Update:

  • Hi still the file is not getting shared.
  • How to modify this line puppet:///modules/module_name/datas.xls the file to be copied is under this location /etc/puppet/modules/mymodule/manifests/datas.xls ?

Error on Client: (Resolved)

root@testing:~# puppetd --test 
err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find class sudo at /etc/puppet/manifests/site.pp:2 on node testing.chn.jd.com
warning: Not using cache on failed catalog
err: Could not retrieve catalog; skipping run

Error 2 on Client:

root@tme13:~# puppetd --test
err: Could not run Puppet configuration client: Could not retrieve local facts: bad URI(is not URI?): http://169.254.169.254/2008-02-01/meta-data/<HTML><HEAD><TITLE>HTTP access denied</TITLE></HEAD><BODY><img src/

New Update:

How to apply this module to all nodes? Such that the file will be copied to all nodes.

share|improve this question
    
... but didnt you already ask this question? askubuntu.com/questions/61080/… –  fossfreedom Dec 23 '11 at 17:25
    
Yes but the solution is not working anymore. –  karthick87 Dec 25 '11 at 4:31
    
Also it is not very clear, the user just copied the content from some websites. –  karthick87 Dec 25 '11 at 17:41
    
Still not a reason to make a new question(?) btw I copied that one from a link Jorge gave me and he told me to c/p it ;) afaik what is in that answer still works!? –  Rinzwind Dec 25 '11 at 19:43
    
here's another reference: serverfault.com/questions/200101/… –  Rinzwind Dec 25 '11 at 19:46
show 7 more comments

1 Answer 1

up vote 13 down vote accepted
+1000

Puppet is a bit of a monster to get your head around, so learning by example is no bad thing. In the below I'm assuming you're using modules - please say in a comment if you're not or if you need more details about how to put the module together.

Let's say you start a new module called mymodule. In the puppet home directory (usually /etc/puppet) on the puppet master you should create the module manifests and files directory:

mkdir -p modules/mymodule/manifests     mkdir -p modules/mymodule/files

Then create a file in that directory named init.pp and enter:

class myfile {
    file { '/home/operator1/Desktop/Backup':
        ensure => directory,
        mode => '0755',
        owner => 'operator1',
        group => 'operator1',
    }

    file { "/home/operator1/Desktop/Backup/datas.xls":
        mode => "0644",
        owner => 'operator1',
        group => 'operator1',
        source => 'puppet:///modules/module_name/datas.xls',
    }
}

Then put the datas.xls file into the module's files directory - in this example in modules/mymodule/files/. (Note there can also be a templates directory for templates).

In the manifests/site.pp file you need to import the module and include the class by doing something like:

import 'mymodule'

node base {
    include myfile
}

node server1 inherits base {}
node server2 inherits base {
    # extra config here
}

Make sure that all your nodes inherit from base and that should be all you need to do. As of puppet 0.25 you can use regular expressions in the node name, eg:

node server[0-9] inherits base {}

Let me know in comments if you require further clarification.

Setting up a client to talk to the puppet master

On the client, you need to do:

sudo apt-get install puppet

Then edit /etc/default/puppet and change START=no to START=yes.

Also edit /etc/puppet/puppet.conf and add a line to the [main] section to tell it where to find the puppet master:

server=puppet.mydomain.com

Then we can do a test run with sudo puppetd --test. If you get key errors you may need to go on to the puppet master server and sign the client key. To check the exact name you can do sudo puppetca --list and then sudo puppetca --sign server1.mydomain.com (or whatever the server name was from the list command).

Now start the puppet service with sudo service puppet start and you should be away. The puppet service will run every hour, so if you update your puppet recipes then all your clients will also be updated.

Deleting Files

I note in the original question you wanted to know how to delete files. You would edit the manifests/init.pp to be

file { "/home/operator1/Desktop/Backup/datas.xls":
    ensure => absent,
}

Other useful tips

If you are having trouble there are a few things you can do. On any machine with puppet installed you can check your syntax by running

puppet --parseonly --ignoreimport myfile.pp

or check the whole lot by taking out the --ignoreimport flag, though that can lead to some funny error messages that aren't really errors I've found. You can also run puppet live on a puppet client machine by doing:

sudo puppetd --test

which shows various useful output, with errors and warnings highlighted in different colours. If you want even more detail you could run:

sudo puppetd --test --debug

but that generally generates so much output that it is hard to wade through, so only do that if you've already tried the previous steps and are stuck and need to see everything being done.

Note this is based on puppet 0.25.x which is what I use at work currently, and is also the version in Ubuntu 10.04. The puppet code in the main section will definitely still work, but later versions of puppet have new flags that can help with debugging output.

share|improve this answer
    
Let me try this solution tonight, and let you know the updates. Thanks a lot :) –  karthick87 Dec 29 '11 at 4:25
    
How to modify this line puppet:///modules/module_name/datas.xls the file to be copied is under this location /etc/puppet/modules/mymodule/manifests/datas.xls –  karthick87 Dec 29 '11 at 10:44
    
The file to be copied should be put in /etc/puppet/modules/mymodule/files/datas.xls - I'll update the answer to be clearer about that. –  Hamish Downer Dec 31 '11 at 14:22
    
Oke thank you,. how to run the manifests? –  karthick87 Dec 31 '11 at 14:54
    
How to apply this module to all nodes from puppetmaster? Instead of applying it to every node forcefully by running puppet agent --test –  karthick87 Jan 15 '12 at 19:10
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.