D
D
demsi2017-05-25 18:34:07
linux
demsi, 2017-05-25 18:34:07

How to check the uniqueness of your resource parameters in puppet?

Created class lb
And defined resource lb::vhost Looks
like this:

define lb::vhost (
    String  $domain              = $title,
    String  $project             = "",
    String  $network             = "",
    String  $ensure              = present,
    String  $syslog_nginx_access = "localhost:518"
    String  $syslog_nginx_error  = "localhost:518",
    Boolean $syslog              = false,
    Hash    $upstream_servvers   = { '127.0.0.1:81' => 1 },
    String  $custom              = "",
) {
        if $project == "" or $network == "" {
            fail("Require params \$project and \$network")
        }
...
...

In site.pp , for example, I connect several of these resources:
node 'test_server' {
    class { 'lb': }

    lb::vhost { 'a.example.com':
        project => 'project1',
        network => 'network1',
    }
    
    lb::vhost { 'b.example.com':
        project => 'project1',
        network => 'network1',
    }
}

And I need it to be impossible to connect the same project and network
values ​​to different domains. And I can’t figure out how I can check the situation in vhost.pp if the same project and network are set for different domains.
There was an idea to create a file somewhere /path/to/project_network. If the file exists, throw an error. But I can't do it like in bash - if .
That is, it turns out that I need to somehow check in puppet :
if файл существует {
   fail("project and network already exists")
}

And I can't figure out how to do it. Well, or how to do it correctly without such crutches as creating a file.
I will be very grateful for advice.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question