# How can I avoid package resource overriding file resource?

For example, I have a file resource:

file { '/var/www':
ensure  => directory,
owner   => david,
group   => david,
before  => Package["httpd"],
}


And I have a package resource:

package { "package name":
ensure  => present,
}


I noticed that the package resource ends up changing /var/www ownership back to root:root

Is there a way I can avoid this?

EDIT: Something I forgot to mention is in this example, my /var/www directory actually acts as a mountpoint for a logical volume. Also I am using roles+profiles convention, and my lvm/mounting related stuff occurs in my 'base' profile. Whereas my package resource is in 'middleware' class. I've set up ordering so that my base profile occurs first, followed by my middleware profile.

Consequently my file resource ends up being ensured before my package resource.

edit retag close merge delete

Sort by » oldest newest most voted

Yeah the ordering is wrong.

Should be:

package { 'package name':
ensure  => present,
before  => File['/var/www'],
}

file { '/var/www':
ensure  => directory,
owner   => david,
group   => david,
}


EDIT:

So my first thought is, do you really need to mount a filesystem over the top of a directory owned by an RPM?

If you do, perhaps the best you can hope for is an Exec:

package { 'httpd':
ensure => present,
}

file { '/var/www':
ensure  => directory,
}

exec { 'chown-var-www':
command => 'chown david:david /var/www',
path    => '/bin',
unless  => 'ls -ld /var/www | grep -q david',
require => Package['httpd'],
}

more

My apologies, I omitted some key info in my original question. I have now added that in.

( 2016-04-21 04:18:29 -0500 )edit

I agree, it would be better to set documentroot away from /var/www, and that might be the better solution, and I'll look to implement that at some point in the future. But I'll use the exec approach for the time being.

( 2016-04-23 05:35:15 -0500 )edit