puppet - Ruby how to extend method to accept new parameter -
i hope can me this.
i have method in ruby:
def puppetrun_oneclass! proxyapi::puppet.new({:url => puppet_proxy.url}).runsingle fqdn end
which call within other method:
def update_multiple_puppetrun_oneclass_deploy if @hosts.map(&:puppetrun_oneclass!).uniq == [true] notice "successfully executed, check reports and/or log files more details" else error "some or hosts execution failed, please check log files more information" end end
where @hosts array of hostnames.
now, extend puppetrun_oneclass! accept @mydeploy parameter, @mydeploy parameter variable containing string.
how that?? , how should call modified method?
thanks!!
you should add argument, means need declare long-form block map
loop.
new method:
def puppetrun_oneclass!(deploy) # ... code using `deploy` variable end
new call:
@hosts.map { |h| host.puppetrun_oneclass!(@mydeploy) }.uniq
note uniq
pretty heavy handed approach here if want see if of them failed. might want try find
stop @ first 1 fails rather blindly executing them all:
!@hosts.find { |h| !host.puppetrun_oneclass!(@mydeploy) }
this ensure none of them returned false condition. if want run them , errors, might try:
failures = @hosts.reject { |h| host.puppetrun_oneclass!(@mydeploy) } if (failures.empty?) # worked else # had problems, failures contains list of failed `@hosts` end
the first part returns array of @hosts
entries failed. might useful capture list , use produce more robust error message, perhaps describing didn't work.
Comments
Post a Comment