Ask Your Question
0

Resource defaults not working for Apache

asked 2015-10-08 18:53:13 -0500

umd_ykatz gravatar image

updated 2015-10-11 02:09:06 -0500

I am using the PuppetLabs apache module. I would like to set SetEnvIf values for ever single vhost.

I set the value in my web_server profile:

class profile::web_server {
    class { 'apache':
        default_vhost => false,
    }

    Apache::Vhost {
        setenvif      => [
            'User-Agent "KEMP 1.0" dontlogkemp dontlog',
            'User-Agent "SearchApp 2.1" dontlogsearchapp dontlog',
        ],
    }
}

My vhosts are defined in other classes, but I want them to inherit this default:

class profile::web_server::cluster {
    apache::vhost { 'clustered site 1':
        ...
    }
    apache::vhost { 'clustered site 2':
        ...
    }
}
class profile::web_server::server1 {
    apache::vhost { 'site 1 on server 1 only':
        ...
    }
    apache::vhost { 'site 2 on server 1 only':
        ...
    }
}
class profile::web_server::server2 {
    apache::vhost { 'site 3 on server 2 only':
        ...
    }
    apache::vhost { 'site 4 on server 2 only':
        ...
    }
    apache::vhost { 'site 5 on server 2 only':
        ...
    }
    apache::vhost { 'site 6 on server 2 only':
        ...
    }
}
...

No matter what I do, it is not added to the config. I tried several other values for testing (port and priority) and none of them seem to work either.

All the sites are behind a load balancer and need this SetEnvIfso that their access logs don't fill up with uptime checks by our load balancer and search engine indexer. The useragent may change or we may add additional ones, so I only want to have it in one place for 100+ vhosts.

Puppet version: 3.8.1


I do have a sort of ugly workaround (which puts the config for the whole apache server instead of for every vhost):

define apache_setenv($setenvif) {
    apache::custom_config { 'setenvif':
        priority => '0',
        content  => template('apache/vhost/_setenv.erb'),
    }
}
apache_setenv(
    setenvif => [
        'User-Agent "KEMP 1.0" dontlogkemp dontlog',
        'User-Agent "SearchApp 2.1" dontlogsearchapp dontlog',
    ]
);
edit retag flag offensive close merge delete

Comments

The code doesn't show any use of apache::vhost. Note that resource defaults have an area of affect based on dynamic scoping, so setting it in one class and expecting to apply to another won't work: https://docs.puppetlabs.com/puppet/4.2/reference/lang_defaults.html#area-of-effect

domcleal gravatar imagedomcleal ( 2015-10-09 05:09:42 -0500 )edit

Updated with location of vhost definitions

umd_ykatz gravatar imageumd_ykatz ( 2015-10-09 08:31:35 -0500 )edit

Added requirement that all 100+ vhosts in multiple classes need same default `SetEnvIf` and the reason for it.

umd_ykatz gravatar imageumd_ykatz ( 2015-10-11 02:11:15 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2015-10-14 00:41:31 -0500

alexandre gravatar image

updated 2015-10-14 00:42:02 -0500

Maybe not the most efficient way because you have to add a line for all your vhost but what about:

class profile::web_server {
   $my_setenvif = [
        'User-Agent "KEMP 1.0" dontlogkemp dontlog',
        'User-Agent "SearchApp 2.1" dontlogsearchapp dontlog',
    ]
}

And for all your vhost:

class profile::web_server::server1 {
  apache::vhost { 'site 1 on server 1 only':
    ...
    setenvif => $profile::web_server::my_setenvif
  }
  apache::vhost { 'site 2 on server 1 only':
    ...
    setenvif => $profile::web_server::my_setenvif
  }
}

But at least, you are sure to use the same value for all your vhost and if you need to modify it, you just have to modify it at one place.

edit flag offensive delete link more
-1

answered 2015-10-09 20:13:09 -0500

lupin gravatar image

updated 2015-10-11 03:38:39 -0500

It should be like.

 class { '::apache':
  default_vhost => false,
} 

apache::vhost { 'clusternode1':
   servername => '127.0.0.1',
   setenvif => [ 'User-Agent "KEMP 1.0" dont logkemp dontlog', ],
   docroot  => '/var/www/html',
}
edit flag offensive delete link more

Comments

That only applies to one vhost, but I have 100 spread through 4 classes that all need the same setenvif directives. (We run a load balancer and don't log the checks that see if the server is up - the useragent can change or there may be additional ones, I want to only set it in one place.)

umd_ykatz gravatar imageumd_ykatz ( 2015-10-11 02:05:16 -0500 )edit

I missed your "4 classes" keyword. If you're creating your vhost using using create_resources you can pass a default parameters where you can put the value of setenvif.

lupin gravatar imagelupin ( 2015-10-11 03:26:46 -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: 2015-10-08 18:46:47 -0500

Seen: 236 times

Last updated: Oct 14 '15