Puppet passing an array to a define to move directories

112 views
Skip to first unread message

mickael avedissian

unread,
Nov 19, 2012, 2:14:29 AM11/19/12
to puppet...@googlegroups.com
Hi,

I'm trying to use puppet to move some folders from one directory to another in Windows.

That being said I have a parameterized define which looks like that:

define module_name::move ($dir_name, $arg2){

$dir_origin = "c:/${dir_name}"
$dir_destination = "c:/tmp/${arg2}"

file { $dir_destination:
  ensure => 'directory',
  mode => '755',
}

exec { $backup_folder :
    command => "cmd.exe /c move $dir_origin $dir_destination",
    path => 'c:\windows\system32;c:\windows',
}
}


and I call the define as follow:
  module_name::move { 'folder_name': 
    dir_name => ['dir1','dir2','dir3'],
    arg2 => blah,
  }


when I execute this code, puppet concatenate the value of $dir_name as dir1dir2dir3 instead of running my define 3 separate times.

I would greatly appreciate getting some help on how I could reach my purpose.

Thanks,
Mike

David Schmitt

unread,
Nov 19, 2012, 6:22:41 AM11/19/12
to puppet...@googlegroups.com

You are passing an array (dir_name) into a single resource. Instead you
want to create three separate resources:

module_name::move { [ dir1, dir2, dir3 ]: ... }


Also, I feel compelled to point out that having verbs or actions as names
of resources is a big red warning flag, that you're doing something outside
the intended design of puppet. e.g. are you aware that your define will try
to move the directories every time you run the agent with this?



Best Regards, David

mickael avedissian

unread,
Nov 19, 2012, 10:22:40 AM11/19/12
to puppet...@googlegroups.com
Thank you for your answer Dave.

This is the intended purpose of having the puppet agent move those folders every time it is called.

Would it be an easier (more proper) way of doing it?

Thanks,
Mike

David Schmitt

unread,
Nov 19, 2012, 12:01:15 PM11/19/12
to puppet...@googlegroups.com
On 2012-11-19 16:22, mickael avedissian wrote:
> Thank you for your answer Dave.
>
> This is the intended purpose of having the puppet agent move those
> folders every time it is called.
>
> Would it be an easier (more proper) way of doing it?


Without knowing your actual requirements, a possible solution might
involve adding a scheduler task that will move the directories every 30
minutes. This would be much more explicit than "whenever puppet is
running", which might be much more often (when
developing/testing/deploying) or much longer (when there's a problem on
the puppet master for example).


Best Regards, David (not Dave).
> --
> You received this message because you are subscribed to the Google
> Groups "Puppet Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/puppet-users/-/pP7RbRfgngIJ.
> To post to this group, send email to puppet...@googlegroups.com.
> To unsubscribe from this group, send email to
> puppet-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/puppet-users?hl=en.

Reply all
Reply to author
Forward
0 new messages