Oooooh. I've never really grokked the defined type stuff. I can see now I
need to dig in and make sense of it.

Thanks, John!


*
*
*Bret Wortman*
<http://damascusgrp.com/>
http://damascusgrp.com/ <http://bretwortman.com/>
http://about.me/wortmanbret


On Mon, Jul 29, 2013 at 1:19 PM, jcbollinger <[email protected]>wrote:

>
>
> On Tuesday, July 23, 2013 12:32:43 PM UTC-5, Bret Wortman wrote:
>>
>> I'm trying to use a puppet manifest to set up a series of backup jobs on
>> servers which are each running a variety of mysql databases. My manifest
>> currently looks something like this, which almost works:
>>
>> class backups () {
>>
>>     Cron {
>>         ensure => present,
>>         user => root,
>>     }
>>
>>     $remote_dest = ['zx2:/data/src/backups','zx3:**/data/backups']
>>
>>     if $hostname == "www" {
>>         $databases = ['phpbb3','wikidb','rt4','**wordpress']
>>         $bkp_dest = "/data/backup"
>>     elsif...
>>     :
>>     }
>>
>>     cron { $databses:
>>         command => "mysqldump --user admin $databases | gzip >
>> mysql-$databases-`date +%Y%m%d`.gz",
>>         hour => 1,
>>         minute => 20,
>>     }
>>
>>     cron { $remote_dest:
>>         command => "rsync -arzv $bkp_dest $remote_dest",
>>         hour => 4,
>>         minute => 40,
>>     }
>> }
>>
>> I get the right number of cron jobs built, but when the array variables
>> are quoted, I get the contents all concatenated together.
>>
>
>
> Yes, that is what you get when you convert an array to a string.
>
>
>
>> What I'd like is to simulate a "for x in array" kind of construct. Is
>> that possible using puppet? I'd rather not have to build this and specify
>> each job by hand, which seems really clunky given the elegance of the tool.
>> I'm sure I'm just not seeing something.
>>
>
>
> There is the template approach you discovered, when it is applicable.  The
> more general approach is to use a defined type in conjunction with Puppet's
> shorthand for declaring multiple resources based on an array of their
> titles.  You're example code is heading in the right direction.  Here's how
> a working version might look:
>
> define backups::database () {
>   cron { "backup_database_${title}":
>
>     ensure  => present,
>     user    => root,
>     command => "mysqldump --user admin ${title} | gzip >
> mysql-${title}-`date +%Y%m%d`.gz",
>     hour    => 4,
>     minute  => 40,
>   }
> }
>
> define backups::remote () {
>   cron { "backup_remote_dest_${title}":
>
>     ensure  => present,
>     user    => root,
>     command => "rsync -arzv ${backups::bkp_dest} ${title}",
>     hour    => 1,
>     minute  => 20,
>   }
> }
>
> class backups {
>   # ...
>   # Set variables, including $databases, $bkp_dest, and $remote_dest
>   # ...
>
>   backups::database { $databases: }
>   backups::remote { $remote_dest: }
> }
>
> Note the use of the automatic $title variable inside the definitions to
> refer to the title of the defined type instance.  You can declare other
> parameters to the definition, too, but as used in the example, all
> instances would get the same values for those parameters.  There are ways
> to be cleverer about that sort of thing, once you have a hold of what's
> going on.
>
>
> John
>
>  --
> You received this message because you are subscribed to a topic in the
> Google Groups "Puppet Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/puppet-users/rm1wx3s4ZiE/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/puppet-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to