• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Urban Penguin

The Urban Penguin - Linux Training

  • Home
  • About
  • Programming
    • Master Editing Text Files Using VIM
    • Learn Shell Scripting with BASH
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell
    • Learn C Programming using Linux and the Raspberry Pi
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
  • OS Tutorials
    • Red Hat and CentOS Training
      • Red Hat Enterprise Linux System Administration 1 – RH124
      • RHCSA – System Admin 2 – RH134
      • RHCE – EX294 – Automation With Ansible
    • Learning Ubuntu
    • LPI Training
      • LPI Linux Essentials
      • LPIC-1 Linux Administrator
      • LPIC-2 Certified Linux Engineer
      • LPIC-3 Senior Level Certification
        • LPIC-3 Exam 300 : Mixed Environments
        • LPIC-3 Exam 303 : Security
        • LPIC-3 Exam 304 : Virtualization and High Availability
    • Linux Technologies
      • Apache HTTPD Server
      • Learning PHP
      • Learning PUPPET
      • Learning SAMBA
      • Linux File-Systems
      • Monitoring with Nagios Core
      • MYSQL
      • openLDAP Directories on Linux
You are here: Home / Linux / Puppet / Puppet Moving Directories

Puppet Moving Directories

March 18, 2016 by The Urban Penguin

Puppet Moving Directories


The task of having Puppet moving directories is a simple one which we demonstrate for you here using file resources. One of the things that a good configuration management system should be able to do is to help you cope with organizational change. In this blog we look at how we can create a simple manifest to simulate moving directories with Puppet. We will, in fact, copy the contents on one directory to another and then delete the original source directory. A simple use case for this is wanting to unify all of the web server document roots. On some systems thus is /var/www, other it is /var/www/html and others is it is /srv/www/htdocs. We can easily copy all if the contents of one of these directories into a new directory that conforms to your new standard of the document root location. We will see that we can copy the directory and the entire contents including sub-directories.

We will be using a simple manifest to show the moving of directories with Puppet, the reality is that this would be part of a larger module but we are just try to show how the Puppet Server could easily manage the task.

To help allow for the scaling out of the manifest into a bigger application we first set two variables. These then could be passed as class parameters to override the defaults that we would code into the module

$source_directory = '/tmp/apt'
$target_directory = 'tmp/aptnew'

The source directory whose content we want to move, we will be moving it to the /tmp/aptnew directory which will  not exist on the system. We then set up file resources for both directories. First the target directory that we need to create:

file { $target_dir :
 ensure => 'directory',
 recurse => true,
 source => "file:///${source_dir}",
 before => File[$source_dir],
}

The syntax for any resource is:

type { 'title':
}

We use the file type and the title is the interpolated variable. We want to ensue that the file resource exists as a directory and then we recursively  copy the contents of the local source directory. Using the file:// protocol we copy from the local file system. We need to make sure that this happen first so we explicitly declare this with the ending before line which references the next resource that we will configure next.

file { $source_dir :
 ensure => 'absent',
 purge => true,
 recurse => true,
 force => true,
}

In this second  file resource the ensure absent line is going to delete this directory, we do this recursive to delete sub-directories and we need to use force with this. The purge is used to delete the file content of the directories.

The complete code is shown below:

Puppet Moving DirectoriesWe can text the manifest that we have created with:

# puppet apply /tmp/file.pp

The video steps you through and explains the process:

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to print (Opens in new window)

Filed Under: Puppet

Primary Sidebar

Newest Video

The Urban Penguin On Youtube

Categories

Pages

  • About The Urban Penguin
  • Contact Us
  • Linux Technologies
    • Apache HTTPD Server
    • Learning PHP
    • Learning PUPPET
    • Learning SAMBA
    • Linux File-Systems
    • Monitoring with Nagios Core
    • MYSQL
    • openLDAP Directories on Linux
  • LPI Training from The Urban Penguin
    • Complete Linux Essentials
    • Live and Pluralsight hosted courses
    • LPI Linux Essentials
    • LPI Linux Essentials for Raspberry Pi
    • LPIC-1 Linux Administrator
    • LPIC-2 Certified Linux Engineer
    • LPIC-3 Senior Level Certification
      • LPIC-3 Exam 300 : Mixed Environments
      • LPIC-3 Exam 303 : Security
      • LPIC-3 Exam 304 : Virtualization and High Availability
  • Online Instructor-led Courses
    • Bash Scripting Masterclass
    • Nftables Masterclass
    • Red Hat Enterprise Linux System Administration 1 – RH124
    • SELinux Masterclass
  • OpenStack
    • Citrix Videos
    • Pluralsight
    • Raspberry Pi Tutorials
    • Udemy
  • Operating System Tutorials
    • Learning SUSE
    • Learning Ubuntu
    • Linux Foundation Training
    • Red Hat and CentOS Training
      • RHCE – EX294 – Automation With Ansible
      • RHCSA – System Admin 1 – RH124
      • RHCSA – System Admin 2 – RH134
    • Solaris 11 OCA 1ZO-821
  • Scripting – the power of repetition!
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
    • Learn C Programming using Linux and the Raspberry Pi
    • Learn Shell Scripting with BASH
    • Master Editing Text Files Using VIM
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell

© 2022 The Urban Penguin · All Rights Reserved