jamtur01 / puppet-rundeck

Puppet integration with RunDeck
Apache License 2.0
45 stars 16 forks source link

Command line interface? #10

Open waldner opened 11 years ago

waldner commented 11 years ago

Is there a way to get the list of hosts as a result of a command, eg command > hostlist.xml in a single operation, without having to run the webserver and get the list through HTTP? Thanks.

jamtur01 commented 11 years ago

There is not currently a way to do this. Patch would be welcomed.

waldner commented 11 years ago

Unfotunately I'm no ruby expert. So far I've been able to introduce the new option (-b or -batch). Next, I thought something like this would work in lib/puppet-rundeck.rb:

get '/' do
  doresponse
end

def self.run!(options={})
  if options[:batch] == 1
    puts doresponse
  else
    super.run! options
  end
end

def doresponse
    response['Content-Type'] = 'text/xml'

where "doresponse" contains the old xml code generation code (omitted above for brevity). I think the idea makes sense. Now this works fine if I'm not using the batch option (ie, the usual webserver behavior), however when I invoke it with -b, I get:

/root/newpuppet/lib/puppet-rundeck.rb:51:in `run!': undefined local variable or method `doresponse' for PuppetRundeck:Class (NameError)
    from bin/puppet-rundeck:68

I suspect there's some scoping issue going on here (which I know in Ruby is a bit tricky), and maybe I'm somehow trying to mix class/instance methods (although I can't really tell for sure). However, I'm confident that a working code is just a few adjustments away. Could you give some hints?