-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENT-12173: Add windows-capabilities and windows-optional-features modules #104
base: master
Are you sure you want to change the base?
ENT-12173: Add windows-capabilities and windows-optional-features modules #104
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mobile review, so super weak. Looks ok. But i can do a better look through tomorrow when at desk
bundle agent windows_capability | ||
{ | ||
methods: | ||
windows.!data:disable_windows_capability_inventory:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you expect this will prevent thw variables in the guarded bundle from being resolved? I expect it wont because od how evaluation is eager to resolve variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh i see, it preventa thw command. From generating the inventory file thats read
"${this.bundle}_cache_file" string => "${sys.statedir}${const.dirsep}${this.bundle}_cache.csv"; | ||
"${this.bundle}_command" string => "Get-WindowsCapability -Online | ConvertTo-Csv -notypeinformation | select-object -skip 1 | Set-Content -Path '${${this.bundle}_cache_file}'", | ||
if => not(fileexists("${${this.bundle}_cache_file}")); | ||
"csv" data => readcsv("${${this.bundle}_cache_file}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this on need to be guarded with if fileexists()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually, I will check if getting all the capabilities is expensive somehow and if not, remove this guard (and the associated rm of the file when I change state). The initial idea was just to leverage readcsv() which only works with files. Then a second idea was to use this file as a cache which could get updated only when needed (state changes) or a timeout (say once a day or something if the getting of capabilities was expensive or hit the network like apt update
might).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this is usually what I do cache for some period of time (usually a day) and then other things like modifying the capabilities could clear the cache as well.
bundle agent _windows_capability_state(capability_name, desired_state) | ||
{ | ||
reports: | ||
"_windows_capability_state, capability_name:${capability_name}, desired_state=${desired_state}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to guard this report with DEBUG or verbos_mode or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, leftover I didn't catch 👍 don't want it there.
commands: | ||
windows.state_not_ok:: | ||
"${operation}-WindowsCapability -Online -Name ${capability_name}" | ||
classes => if_ok("state_changed"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if_ok will define a namspace scoped class. Since you are not namespacing this bundle that means you will have the class default:state_changed
defined which is quite generic and could trigger other unintended effects.
I recommend using results( "bundle", "state" ) or similar which would define stat_repaired
(if_ok defines the class if the promise is kept OR repaired iirc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
windows:: | ||
"${this.bundle}_cache_file" string => "${sys.statedir}${const.dirsep}${this.bundle}_cache.csv"; | ||
"${this.bundle}_command" string => "Get-WindowsOptionalFeature -Online | ConvertTo-Csv -notypeinformation | select-object -skip 1 | Set-Content -Path '${${this.bundle}_cache_file}'"; | ||
"csv" data => readcsv("${${this.bundle}_cache_file}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to be guarded with if => fileexists()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, that is an improvement to the pattern I made in capabilities, will include here.
windows:: | ||
"if((Get-WindowsOptionalFeature -Online -FeatureName ${feature_name} | select-object -expandproperty state) -ne '${state_name}'){exit 0}else{exit 1}" | ||
contain => powershell, | ||
classes => kept0_repaired1("state_not_ok","state_ok"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is body classes kept0_repaired1 defined? I was going to check and see if the classes defined were namespace or bundle scoped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, I haven't gotten through optional features fixup yet
No description provided.