title: How to execute scripts sequentially in a loop with Puppet?
body: <p>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.</p>
  
  <p>Here is what I tried:</p>
  
  <pre><code>$ cat test.pp
  define my_test {
     exec { "my test task $name":
          provider =&gt; shell,
          logoutput =&gt; true,
          command =&gt; "sleep $name &amp;&amp; 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
  </code></pre>
  
  <p>I have also tried with a <code>[3, 2, 1, 0].each |$var| { ... }</code> construct, and read <a href="https://docs.puppetlabs.com/puppet/latest/reference/lang_iteration.html" rel="nofollow">the docs</a> and <a href="https://ttboj.wordpress.com/2013/11/17/iteration-in-puppet/" rel="nofollow">ttboj's very detail article on loops in Puppet</a>, but I still don't get it.</p>
  
  <p>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 ?</p>