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

Sooo i have this hash in app1's puppet manifest

$applicaton = 'app1'

daemontools::build {
    $application:
        path     => "/opt/supervise/${application}"
        envvars  => {
            'ENVIRONMENT'              => $location,
            'SERVICE_USER'             => $application_user,
            'SERVICE_PORT'             => $gunicorn_port,
            'SERVICE_IP'               => $gunicorn_ip,
            'ADDITIONAL_PARAMS'        => "--workers $processorcount",
            'DJANGO_SETTINGS_MODULE'   => "${application}.settings",
        }
}

and this hash in my app2's puppet manifest

$applicaton = 'app2'

daemontools::build {
    $application:
        path     => "/opt/supervise/${application}"
        envvars  => {
            'ENVIRONMENT'              => $location,
            'SERVICE_USER'             => $application_user,
            'SERVICE_PORT'             => $gunicorn_port,
            'SERVICE_IP'               => $gunicorn_ip,
            'ADDITIONAL_PARAMS'        => "--workers $processorcount",
            'DJANGO_SETTINGS_MODULE'   => "${application}.settings",
        }
}

which are both passed to daemontools::build ( along with a path )

define daemontools::build (
$envvars = {},
$path
){
    $env_names = keys($envvars)
    daemontools::envfile { $env_names:
        path   => $path,
        value  => $envvars
    }
}
define daemontools::envfile($path, $value) {
    file { "/${path}/envdir/${name}" :
        mode    => 0644,
        content => "${value[$name]}";
    }
}

which results in

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate declaration: Daemontools::Envfile[SERVICE_IP] is already declared in file daemontools/manifests/build.pp:53; cannot redeclare at daemontools/manifests/build.pp:53

How can i make it so that i wont get duplicate resource declarations?

share|improve this question

3 Answers 3

In the creation of your daemontools::envfile object, you should add a unique identifier to the $name of the object.

daemontools::envfile { $something_unique$env_names:
    path   => $path,
    value  => $envvars
}

By default, $name is each of your $env_names. When you create the second object with the same set of keys, it causes many duplicates. FQDN or something equally unique could be useful for lookup.

share|improve this answer

Right, you're using $env_names (you may also want to look at consistent use of underscores there) as the $name for daemontools::envfile for semi-hacky iteration - I assume you don't want to use the future parser (quite reasonably). Note that also what you're trying to do with value => $envvars probably won't work either.

So, prefix from puppetlabs/stdlib is your friend for the duplicate issue, ensuring you get unique $names by preconstructing the path:

define daemontools::build (
    $envvars = {},
    $path
) {
    $envnames = keys($envvars)
    $envfiles = prefix($envnames, "${path}/envdir/")
    daemontools::envfile {
        $envfiles:
            # Stuff
    }
}

However, this will probably just reveal that value => $envvars doesn't work, and seems to only lead to the conclusion that you need the future parser for now, and each()

share|improve this answer
    
definitely got me headed in the right direction. :) thanks –  Arenstar Feb 14 at 4:44

It seems this worked :) Although messy with that inline template...

    $env_names = keys($envvars)
    $prefixedenvnames = prefix($env_names, "${path}/envdir/")
    daemontools::envfile { $prefixedenvnames:
        value  => $envvars
    }
}

define daemontools::envfile($value) {
    $tmp = inline_template('<%= name.split("/").last %>')
    file { $name :
        mode    => 0644,
        content => "${value[$tmp]}";
    }
}
share|improve this answer

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.