On Feb 8, 4:11 am, sateesh <bbalasate...@gmail.com> wrote: > Hi, > > I have written a sample manifest in puppet using Ruby DSL. I want to > build a looping functionality. But I am getting problem as shown > below: > > root@puppet-swproxy:/tmp# cat test.rb > hostclass :test do > $abc = ["a","b"] > $abc.each do |sip| > create_resource :exec, "echoabc", :command => "echo #{sip}" > end > > file "/tmp/testecho.txt", :content => "This is test file", :require => > Exec['echoabc'] > end > > node "default" do > include "test" > end > root@puppet-swproxy:/tmp# puppet apply --verbose test.rb > Duplicate definition: Exec[echoabc] is already defined on node puppet- > swproxy.persistent.co.in
This is not a problem with looping per se. In fact, it shows that your looping construct is itself working exactly the way it should. > I can make the echoabc as dynamic, And you need to do that, because every resource in the compiled catalog needs a distinct title. > but how can specify that in require > in next statement (file). I need to execute the file only after > executing the exec. You need to manage the file only after executing *which* Exec? You declare two distinct ones, even if you try to give them the same title. > So what I need to do. Generall the puppet will not > run in the synchronized way. I observed that the statements are > executed asynchronously. Puppet runs completely synchronously, but the order in which it applies resources is essentially unpredictable in the absence of declared resource relationships. That's very different from asynchronous operation, which would mean that Puppet applies multiple resources concurrently (i.e. via threads or multiple child processes), which it absolutely does not do. If you only need one Exec, then move its declaration out of the loop and all will be well. If you need multiple Execs, and you need them all to run before the file is managed, then create an array before the loop, in your loop add each Exec to it, and make your file require the whole array. > Also, I need to define the Exec path at the top as I specified in the > pp file. > > Exec { > path => ["/bin", "/sbin", "/usr/bin", "/usr/sbin"], > } > > How to write this in Ruby DSL. So that I can eliminate the path > attribute in all exec statements. Is there some reason why you actually need to use Ruby DSL instead of Puppet DSL? I don't see one in what you presented so far, and I would definitely stick to Puppet DSL unless you have no alternative. Here's one way to implement your example in Puppet DSL: modules/test/manifests/exececho.pp: ------ define test::exececho() { exec { "echo_${name}": command => "echo ${name}", path => ['/bin', '/sbin', '/usr/bin', '/usr/sbin'], tag => test_tag, } } modules/test/manifests/init.pp: ------ class test { test::exececho { ['a', 'b']: } file { '/tmp/testecho.txt': content => "This is test file" } Exec<| tag == 'test_tag' |> -> File['/tmp/testecho.txt'] } If you needed the resource defaults for other Execs as well, then you you could define them at the top of class 'test' instead of in the test::exececho definition, and they would apply to all Exec resources declared within the scope of class 'test'. If you want those defaults to be global (defaults) for all Execs in your configuration, then just put the resource defaults in site.pp, outside any class. John John -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.