Ask Your Question
0

puppet hash iterate create file

asked 2014-02-13 10:27:42 -0500

Arenstar gravatar image

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 ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2014-02-13 11:34:48 -0500

Arenstar gravatar image

It seems this worked :)

    $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]}";
    }
}
edit flag offensive delete link more

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: 2014-02-13 10:27:42 -0500

Seen: 301 times

Last updated: Feb 13 '14