Ask Your Question

How to create directory before mount in hieradata

asked 2016-02-19 10:32:51 -0600

kshannon_ffn gravatar image


I'm a bit of a puppet noob... From a yaml in hieradata I know how to both create a directory & to create a mount. However, I'm unsure how to force the ordering of these from within a yaml.

The only solution I could come up with is to create a module I called ramdisk just to order these properly. It does what I want... But what if I want to create a second directory/mount? I don't want to create a new module. Can someone please point me to documentation that will help me learn how to make this more generic so I can pass the arguments required to it.

Here's what I have...

class ramdisk {
file { '/local/common/ramcache':
ensure => 'directory',
owner  => 'nobody',
group  => 'nobody',
mode   => '0750',
before => Mount['/local/common/ramcache'],
} ->

mount { '/local/common/ramcache':
ensure => 'mounted',
atboot => 'true',
device => 'none',
fstype => 'tmpfs',
options => 'nodev,nosuid,noexec,nodiratime,size=10M',
dump   => '0',
pass   => '0',
require => File['/local/common/ramcache'],


edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-19 19:47:53 -0600

You'd use a defined type and create_resources.

define file_and_mount (
) {
  file { $name:
    ensure => 'directory',
    owner  => $owner,
    group  => $group,
    mode   => $mode,
  mount { $name:
    ensure  => 'mounted',
    atboot  => $atboot,
    device  => $device,
    fstype  => $fstype,
    options => $options,
    dump    => $dump,
    pass    => $pass,
    require => File[$name],

Then in your manifest somewhere:

class myclass (
) {
  create_resources('file_and_mount', $files_and_mounts)

And in Hiera somewhere:

    owner: nobody
    group: nobody
    mode: 0750
    atboot: true
    device: none
    fstype: tmpfs
    options: 'nodev,nosuid,noexec,nodiratime,size=10M'
    dump: 0
    pass: 0
    owner: ...
    group: ...
    mode: ...
    atboot: ...
    device: ...
    fstype: ...
    options: '...'
    dump: ...
    pass: ...

Notice that I cleaned up your relationships. I deleted the redundant "before" and the redundant ->.

edit flag offensive delete link more


Hey wow thanks so much for the answer!! I was not expecting someone to go this far into answering it. Very much appreciated good sir. This is exactly what I was looking for...Will help me learn to create my own modules.

kshannon_ffn gravatar imagekshannon_ffn ( 2016-02-22 16:21:55 -0600 )edit

This solution does not work, you set the permissions of the underlying directory and then mount to that directory. Now the permissions of the mount differ from the permissions of the directory. When this runs again it will overwrite the mount point with the permissions of the underlying directory.

puser gravatar imagepuser ( 2016-12-21 08:36:34 -0600 )edit

That's a good point. I interpret this question to be about how to refactor the code in the way specified. If the question was about how to do LVM, I would start with the LVM forge module.

Alex Harvey gravatar imageAlex Harvey ( 2016-12-21 20:48:45 -0600 )edit

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


Asked: 2016-02-19 10:32:51 -0600

Seen: 1,218 times

Last updated: Feb 19 '16