change order of elements

39 views
Skip to first unread message

Helmut Schneider

unread,
Jun 19, 2016, 8:12:54 AM6/19/16
to puppet...@googlegroups.com
Hi,

Given the following structure:

hiera.yaml:
[...]
:hierarchy:
- nodes/%{::fqdn}
[...]
- common
:merge_behavior: deeper

common.yaml:
[...]
profiles:
webserver:
apache:
modules:
- auth_kerb
- authnz_ldap
- cgid
- status

host.yaml:
profiles:
webserver:
apache:
modules:
- mpm_event
- php
- ssl

hiera_hash ('profiles')['webserver']['apache']['modules'] returns the
following array:

[auth_kerb, authnz_ldap, cgid, status, mpm_event, headers, proxy,
proxy_http, rewrite, ssl]

mpm_event may also be mpm_prefork and mpm_worker.

How can I ensure that mpm_* is always the first element in the array?

Thank you

Peter Kristolaitis

unread,
Jun 19, 2016, 4:08:18 PM6/19/16
to puppet...@googlegroups.com
Assuming you're trying to solve the problem I think you're trying to
solve (i.e. to have Apache with the correct process model installed
before any additional modules), it's important to note that reordering
the array doesn't guarantee that. The order in which Puppet applies
resources is non-deterministic unless you have explicit ordering.

You're probably better off solving this problem in a different way; for
example by creating a new data element (e.g.
profiles::webserver::apache::process_model), and then specifying
explicit ordering between the process_model package and the modules
packages.

This also gives you the added advantage that it becomes impossible to
have multiple process models listed for a given node, assuming that you
make the new data element a string rather than an array (since it will
get overridden instead of merged).

If my understanding of your problem is incorrect, perhaps you could
describe the problem you're trying to solve. Relying on the order of
array elements is probably a poor approach in the Puppet model, so there
might be a different way to solve the problem.

Helmut Schneider

unread,
Jun 20, 2016, 1:16:52 PM6/20/16
to puppet...@googlegroups.com
Peter Kristolaitis wrote:

> > How can I ensure that mpm_* is always the first element in the
> > array?
>
> Assuming you're trying to solve the problem I think you're trying to
> solve (i.e. to have Apache with the correct process model installed
> before any additional modules), it's important to note that
> reordering the array doesn't guarantee that. The order in which
> Puppet applies resources is non-deterministic unless you have
> explicit ordering.
>
> You're probably better off solving this problem in a different way;
> for example by creating a new data element (e.g.
> profiles::webserver::apache::process_model), and then specifying
> explicit ordering between the process_model package and the modules
> packages.

I'm using puppetlabs/apache to install apache. I already created 4
classes, apache24::install, apache24::modules, apache24::default_hosts
and apache::config to ensure the ordering of the installation process.

apache24::install includes apache{}, where I define "mpm_module =>
false," to be able to provide my own mpm_ module.

Then I call apache24::modules to install the appropriate mpm_ and other
modules.

Obviously the installation of cgi(d) checks the installation of a mpm_
module:

Error: Could not retrieve catalog from remote server: Error 400 on
SERVER: Could not find resource 'Class[Apache::Mod::Prefork]' for
relationship on 'Class[Apache::Mod::Cgi]' on node myhost

I therefore need to ensure that before all other modules an appropriate
mpm mpdule is installed

I helped mysqlf with

# mpm must be the first module to install
if /(mpm_.*)/ in $apacheModules {
$mpmModule = [ $1 ]
$apacheModulesTemp = delete($apacheModules, $mpmModule)
} else {
$apacheModulesTemp = $apacheModules
}
[...]
$apacheModulesRevised = concat($mpmModule, $apacheModulesTemp)

but was wondering if there is an easier/cleaner/better solution.

Peter Kristolaitis

unread,
Jun 20, 2016, 2:03:40 PM6/20/16
to puppet...@googlegroups.com

On 2016-06-20 01:16 PM, Helmut Schneider wrote:
> Peter Kristolaitis wrote:
>
>>> How can I ensure that mpm_* is always the first element in the
>>> array?
>> Assuming you're trying to solve the problem I think you're trying to
>> solve (i.e. to have Apache with the correct process model installed
>> before any additional modules), it's important to note that
>> reordering the array doesn't guarantee that. The order in which
>> Puppet applies resources is non-deterministic unless you have
>> explicit ordering.
>>
>> You're probably better off solving this problem in a different way;
>> for example by creating a new data element (e.g.
>> profiles::webserver::apache::process_model), and then specifying
>> explicit ordering between the process_model package and the modules
>> packages.
> I'm using puppetlabs/apache to install apache. I already created 4
> classes, apache24::install, apache24::modules, apache24::default_hosts
> and apache::config to ensure the ordering of the installation process.
>
> apache24::install includes apache{}, where I define "mpm_module =>
> false," to be able to provide my own mpm_ module.
>
> Then I call apache24::modules to install the appropriate mpm_ and other
> modules.
>
>

Why wouldn't you just set a value for apache::mpm_module? You're trying
to re-implement functionality that's already handled by the apache
module (and has been tested by a bunch of other people).

From a higher-level logical model perspective, this makes more sense --
installing an MPM is part of the basic installation of Apache (you must
have exactly one MPM configured for the system to do anything useful),
so it belongs in the module that does "install Apache".

Even though technically MPM is implemented as modules on the vast
majority of systems, it's a very different kind of module than, say,
mod_rewrite, and should be treated differently.

Reply all
Reply to author
Forward
0 new messages