I'm a very new to Puppet, but I cannot wrap my head around this simple problem: I want to define a resource that simply execute a sequence of scripts, one after the other, waiting for one's execution to finish before launching the next.
Here is what I tried:
$ cat test.pp
define my_test {
exec { "my test task $name":
provider => shell,
logoutput => true,
command => "sleep $name && echo slept for $name seconds",
}
}
my_test { [3, 2, 1, 0]: }
$ puppet apply test.pp
Notice: Compiled catalog for my.domain.fr in environment production in 0.05 seconds
Notice: /Stage[main]/Main/My_test[0]/Exec[my test task 0]/returns: slept for 0 seconds
Notice: /Stage[main]/Main/My_test[0]/Exec[my test task 0]/returns: executed successfully
Notice: /Stage[main]/Main/My_test[3]/Exec[my test task 3]/returns: slept for 3 seconds
Notice: /Stage[main]/Main/My_test[3]/Exec[my test task 3]/returns: executed successfully
Notice: /Stage[main]/Main/My_test[1]/Exec[my test task 1]/returns: slept for 1 seconds
Notice: /Stage[main]/Main/My_test[1]/Exec[my test task 1]/returns: executed successfully
Notice: /Stage[main]/Main/My_test[2]/Exec[my test task 2]/returns: slept for 2 seconds
Notice: /Stage[main]/Main/My_test[2]/Exec[my test task 2]/returns: executed successfully
Notice: Finished catalog run in 6.27 seconds
I have also tried with a [3, 2, 1, 0].each |$var| { ... }
construct, and read the docs and ttboj's very detail article on loops in Puppet, but I still don't get it.
My issue has probably more to do with how Puppet resources work in the end, but could someone explain what is the simplest way to write such a simple task ?