Software & AppsOperating SystemLinux

How To Copy Files to All Machines Using Puppet Master?

Ubuntu 14

Puppet is a powerful configuration management tool that allows you to automate the management and configuration of server operations. One common use case is distributing files across multiple machines. In this article, we will walk you through the steps to copy files to all machines using Puppet Master.

Quick Answer

To copy files to all machines using Puppet Master, you need to create a new module, define a class that specifies the file and its destination location, add the file to the module, import the module and include the class in the site.pp file, and apply the changes by restarting the Puppet service on the Puppet Master and running the Puppet agent on the client machines.

Getting Started

Before we begin, ensure that Puppet Master and Puppet agents are properly installed and configured on your systems. The Puppet Master should be able to communicate with all Puppet agents. If you need help setting up Puppet, you can refer to the official Puppet documentation.

Step 1: Creating a New Module

First, we’ll create a new module on the Puppet Master. A module is a collection of manifests and data (such as facts, files, and templates). In our case, we’ll call our module mymodule.

Navigate to the Puppet home directory and create a new directory for your module:

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

Step 2: Defining a Class

Next, we’ll define a class in a manifest file. A class is a named block of Puppet code and is the primary means by which Puppet Master distributes resources.

In the manifests directory, create a new file named init.pp:

nano /etc/puppet/modules/mymodule/manifests/init.pp

In this file, define a class that specifies the file to be copied and its destination location on the client machines:

class mymodule::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/mymodule/datas.xls',

In this class, we are defining two resources of type file. The first resource ensures that the directory /home/operator1/Desktop/Backup exists. The ensure => directory parameter ensures the directory’s existence, and mode, owner, and group parameters set the permissions and ownership.

The second resource is the file that we want to distribute. The source parameter specifies the location of the file on the Puppet Master.

Step 3: Adding the File to the Module

Now, add the file you want to distribute (datas.xls) to the files directory of the mymodule module:

cp /path/to/datas.xls /etc/puppet/modules/mymodule/files/datas.xls

Step 4: Importing the Module and Class

Next, we need to import our module and include our class in the site.pp file. This file is the main entry point for Puppet Master and is used to map nodes to classes.

Open the site.pp file:

nano /etc/puppet/manifests/site.pp

And add the following lines:

import 'mymodule'

node default {
 include mymodule::myfile

Here, import 'mymodule' imports our module, and include mymodule::myfile includes our class. The node default block applies the class to all nodes.

Step 5: Applying the Changes

Finally, apply the changes by restarting the Puppet service on the Puppet Master:

sudo service puppetmaster restart

On the Puppet agents, run the Puppet agent to fetch the updated configuration:

sudo puppet agent --test

The Puppet agent will now copy the datas.xls file from the Puppet Master to the specified location on all client machines.


In this article, we have walked you through the process of copying files to all machines using Puppet Master. This process is an integral part of managing and configuring servers in a distributed system. By using Puppet, you can ensure that all your machines have the same configuration and files, thereby reducing errors and increasing efficiency.

What is Puppet Master?

Puppet Master is a component of Puppet that acts as a central control point for managing and distributing configurations to Puppet agents on multiple machines.

How does Puppet Master communicate with Puppet agents?

Puppet Master communicates with Puppet agents using a client-server model. Agents send requests to the Puppet Master, and the Puppet Master responds with the necessary configurations and instructions for the agents to apply.

Can I distribute files to specific machines instead of all machines?

Yes, you can distribute files to specific machines by specifying the target nodes in the site.pp file. Instead of using node default, define separate node blocks for each set of machines and include the desired class or module accordingly.

How can I verify if the file distribution was successful?

After running sudo puppet agent --test on the Puppet agents, you can check the logs on both the Puppet Master and the Puppet agents for any errors or warnings related to the file distribution. Additionally, you can manually check the destination location on the client machines to see if the file has been copied successfully.

Can I distribute multiple files using the same module?

Yes, you can distribute multiple files using the same module. Simply add the additional files to the files directory of the module and define the corresponding resources in the class manifest file. Each file resource should have a unique source location and destination path.

Leave a Comment

Your email address will not be published. Required fields are marked *