Ask Your Question
0

Using directory purge on Windows

asked 2015-12-22 09:21:56 -0500

RMJ gravatar image

I am getting started with puppet 3.8.4, and am initially using it to manage the public desktop shortcuts. I have defined a couple classes some that drop pre-prepared shortcuts on the desktop, and some that generate .rdp files from a template. Here are a pair of examples, slightly sanitized:

 class helpshortcuts {
    file { 'c:/users/public/desktop/<myfilename>.url':
            ensure => present,
            source_permissions => ignore,
            source => 'puppet:///modules/helpshortcuts/<myfilename>.url',
         }
    file { 'c:/users/public/desktop/<a different file>.lnk':
            ensure => present,
            source_permissions => ignore,
            source => 'puppet:///modules/helpshortcuts/<a different file>.lnk',
          }
}

and a .rdp example:

class homeservers::<virtualservername> {
    $multimon = 1
    $homeserver = <VirtualServerName>
    file { "c:/users/public/desktop/${homeserver}.rdp":
        ensure => present,
        replace => false,
        source_permissions => ignore,
        content => template('homeservers/homeserver.rdp.erb'),
    }
}

A desktop can have multiple sets of shortcuts and zero to several virtual server connections. My reading of the docs is that all I need to do to a host is apply a class like this:

class publiccontrol {
    file {  "c:/users/public/desktop/":
        ensure => directory,
        purge => true,
        recurse => true,
        }
}

and everything on the public desktop except the stuff I have put there will disappear, however this is not happening. If puppet randomly applies the directory first then everything disappears and subsequently is rebuilt. If puppet applies the directory last, everything is purged off the desktop. If it's somewhere in between you end up with some stuff being purged. If this is not the way to go about this, how can I make sure that only the files put on the desktop are from the classes I assign to the host?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-01-13 21:12:48 -0500

Areson gravatar image

In order be sure that the desktop folder resource is applied first (and that the desktop folder is present), you'll need to setup a dependency between the file resources that are being created on the desktop and the desktop resource. You can do this by setting the require metaparameter on your file resources:

file { "c:/users/public/desktop/${homeserver}.rdp":
         ensure => directory,
         purge => true,
         recurse => true,
         require => File["c:/users/public/desktop"]
}

This will ensure that your folder resource is applied first and that your other file resources will not be applied until after the folder resource is applied, and only if the folder resource was applied successfully. You can also setup this up using chaining instead. See the Puppet Documentation for details

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2015-12-22 09:21:56 -0500

Seen: 52 times

Last updated: Dec 22 '15