Is there a way to create a file only under certain conditions?

I would like to check if a certain device exists and the config file is still missing. If the file ist missing, create the file and update the initramdisk. (This device exists only on our notebooks, otherwise it is a desktop and nothing should be done)

This is our first try:

class hibernate {

        notice("hibernate")

        exec { "echo":
                alias       => "echo",
#               onlyif      => "test -b /dev/mapper/swap_crypt -a ! -f 
/etc/initramfs-tools/conf.d/resume" ,
#               onlyif      => "true" ,
                onlyif      => "false" ,
        }

# should not be created as Exec["echo"] is "false"!
# ... but "resume" is still created
        file { "resume":
                name   => "/etc/initramfs-tools/conf.d/resume",
                source => "puppet:///modules/hibernate/resume",
                mode   => 644,
                require => Exec["echo"],
        }

# should not be execute as Exec["echo"] is "false"!
# ... but is executed because "resume" had been created
        exec { "update-initramfs":
                name => "update-initramfs -u",
                refreshonly => true,
                subscribe   => File["resume"],
        }


}

Even Exec["echo"] is not beeing executed, the file "resume" will be created and "update-initramfs" is executed.


The workaround is to avoid the file-type an simple use an exec with an "echo .. > file" in it.

class hibernate {

        exec { "echo RESUME=/dev/mapper/swap_crypt > 
/etc/initramfs-tools/conf.d/resume":
                alias       => "echo",
                onlyif      => "test -b /dev/mapper/swap_crypt -a ! -f 
/etc/initramfs-tools/conf.d/resume" ,
        }

# if "onlyif" is successful, then Exec["update-initramfs"] is triggerd
        exec { "update-initramfs":
                name => "update-initramfs -u",
                refreshonly => true,
                subscribe   => Exec["echo"],
        }

}


Is there any way to use something like "refreshonly" also for File?

Patrick


--
You received this message because you are subscribed to the Google Groups "Puppet 
Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to 
puppet-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/puppet-users?hl=en.

Reply via email to