Ask Your Question
0

How can I avoid package resource overriding file resource?

asked 2016-04-20 11:41:23 -0500

schowdhury gravatar image

updated 2016-04-21 04:17:25 -0500

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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-04-20 21:31:30 -0500

updated 2016-04-21 12:24:21 -0500

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'],
}
edit flag offensive delete link more

Comments

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

schowdhury gravatar imageschowdhury ( 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.

schowdhury gravatar imageschowdhury ( 2016-04-23 05:35:15 -0500 )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

Stats

Asked: 2016-04-20 11:41:23 -0500

Seen: 65 times

Last updated: Apr 21 '16