Require file for mount and also update the file after mount

puppet

I am trying to make sure a directory exists for a mount and then also update the permissions of that directory after the mount happens. I am receiving the following error:

err: Failed to apply catalog: Cannot alias File[pre_eos_mount] to ["/var/tmp/eos"] at /etc/puppet/modules/mymodule/manifests/eos.pp:29; resource ["File", "/var/tmp/eos"] already declared at /etc/puppet/modules/mymodule/manifests/eos.pp:47

I would like to do something like this:

file { $eos_mount :
    ensure  => 'directory',
    mode    => '1777',
    owner   => 'root',
    group   => 'root',
  }

  mount { $eos_mount :
    ensure  => 'mounted',
    device  => $lv_device,
    fstype  => $fstype,
    options => 'defaults,noatime,nodiratime',
    require => File[$eos_mount],
    notify  => File['post_eos'],
  }

  file { 'post_eos' :
    path    => $eos_mount,
    ensure  => 'directory',
    mode    => '1777',
    owner   => 'root',
    group   => 'root',
  }

What is a way to ensure permissions of a folder after it has been mounted?

Best Answer

In puppet 3+ you can modify an existing resource like so:

See the documentation here for more details

file { $eos_mount :
  ensure  => 'directory',
  mode    => '1777',
  owner   => 'root',
  group   => 'root',
}

mount { $eos_mount :
  ensure  => 'mounted',
  device  => $lv_device,
  fstype  => $fstype,
  options => 'defaults,noatime,nodiratime',
  require => File[$eos_mount],
  notify  => File['post_eos'],
}

File[$eos_mount] {
  path    => $eos_mount,
  ensure  => 'directory',
  mode    => '1777',
  owner   => 'root',
  group   => 'root',
}