2

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?

4
  • Could you 'cheat' and just setup an exec resource with a command of mkdir -p $eos_mount, which would just create the directory if it didn't already exist? Commented Sep 24, 2012 at 23:47
  • 1
    I guess. But that seems like a cheap way out. I'll give it a try though, especially since the first creation of it doesn't matter much since the permissions part is more important after it is mounted. Commented Sep 25, 2012 at 3:31
  • 1
    exec is a hack, but it's the only way to do it besides running Puppet multiple times. Puppet doesn't provide a way to apply the same resource from the catalog multiple times, even in different run stages. Commented Sep 29, 2012 at 18:49
  • I wonder if this could be achieved by the stdlib anchor class - forge.puppetlabs.com/puppetlabs/stdlib Commented Sep 30, 2012 at 3:31

3 Answers 3

0

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', } 
2
  • Interesting. I never noticed that par tof the docs before. New as of Puppet 3.x? I'll give it a try in a couple days once I get back into this part of my Puppet code. Commented Jun 12, 2013 at 23:30
  • This answer is fundamentally wrong for the question. Your second declaration is identical to the first, which is allowed. But declarations of existing resources may not remove existing attributes or change their values (unless overriding default ones). Further, a second declaration does not alter the timing of the resource's creation. So if this works, it's a coin-toss. Commented Dec 22, 2020 at 23:34
0

I'd rather use the module: puppet-name_service_lookups and do something like:

$user_info = getpwnam($owner) $user_uid = $user_info['uid'] $group_info = getgrnam($group) $group_gid = $group_info['gid'] 

and in the options for mount, do:

options => "defaults,noatime,nodiratime,uid=${user_uid},gid=${group_gid}", 
-1

As far as I understand from the error the problem is that you already defined the resource file {'/var/tmp/eos': } somewhere before so puppet master won't let you compile the catalog, because a resource has to be unique (resource type + $name).

In such a case when you have a potential conflict of same resources you should use virtual resources, which guarantee that it's only added once in the catalog, regardless how many time you include it.

1
  • You appear to have read the error message and paid absolutely no attention to what the OP is actually trying to do. Commented Sep 29, 2012 at 18:51

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.