I'm trying to update an existing mcollective inventory script. The script currently gathers information about available updates. I want to replace certain "true" values with markup that will produce a checkbox when copied into my wiki. Here is a simplified version (fewer fields) of my current script.
# patching_inventory.mc
inventory do
puts "||Server||Update Needed||Package Count||Kernel Release||"
format "|%s|%s|%s|%s|"
fields { [
identity,
facts["apt_has_updates"],
facts["apt_updates"],
facts["kernelrelease"]
] }
end
I want to replace the values in the Update Needed
column with {checkbox}done{checkbox}
, but only when update needed is true. Otherwise a placeholder (such as '-') will work. Output looks like this:
||Server||Update Needed||Package Count||Kernel Release||
|host1|true|26|3.20.96|
|host2|false|0|4.18.120|
|host3|true|109|3.21.17|
...
|host197|true|26|3.20.96|
And I want it to look like this:
||Server||Update Needed||Package Count||Kernel Release||
|host1|{checbox}done{checkbox}|26|3.20.96|
|host2|-|0|4.18.120|
|host3|{checbox}done{checkbox}|109|3.21.17|
...
|host197|{checbox}done{checkbox}|26|3.20.96|
My initial attempt was to do something like this:
inventory do
updates = (facts["apt_has_updates"] == 'true') ? "{checkbox}done{checkbox}" : '-'
puts "||Server||Update Needed||Package Count||Kernel Release||"
format "|%s|%s|%s|%s|"
fields { [
identity,
updates,
facts["apt_updates"],
facts["kernelrelease"]
] }
end
But it occurs to me that the inventory do
is maybe not iterating like my non-ruby mind assumed it would be. Yet somewhere, there must be iteration happening because the format string is used many times with different facts. Is there a way to tell the formatter to substitute values for each fact as I have attempted above?
Can any of you point me in the right direction?