Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  Zoredache Sep 24 '12 at 23:47
    
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. –  Andy Shinn Sep 25 '12 at 3:31
    
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. –  jgoldschrafe Sep 29 '12 at 18:49
    
I wonder if this could be achieved by the stdlib anchor class - forge.puppetlabs.com/puppetlabs/stdlib –  Andy Shinn Sep 30 '12 at 3:31

2 Answers 2

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',
}
share|improve this answer
    
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. –  Andy Shinn Jun 12 '13 at 23:30

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.

share|improve this answer
    
You appear to have read the error message and paid absolutely no attention to what the OP is actually trying to do. –  jgoldschrafe Sep 29 '12 at 18:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.