Craig
Craig

Reputation: 58

batch not_if guard says "action run" rather than "skipped"

I have a PS script in recipe that causes chef-run to fail if a certain Security Policy is enabled (basically this problem).

So I have added a not_if guard

  powershell_script 'scheduled-tasks' do
    guard_interpreter :powershell_script
    cwd 'C:\Temp'
    code <<-EOH
      schtasks.exe /create ...
      schtasks.exe /create ...
    EOH
    not_if "(get-itemproperty 'HKLM:\\System\\CurrentControlSet\\Control\\Lsa').DisableDomainCreds -eq '1'"
  end

I am using Test-Kitchin, VirtualBox and Windows VMs. Running the powershell command 'getitemproperty...' returns True meaning it is Enabled and thus I do not want the script run and expect Chef to say 'skipped due to not_if'.

However, in the terminal output it says "action run".

The chef run doesn't fail so the script cannot have run, but why does it not say "skipped"?

Regards

Upvotes: 0

Views: 188

Answers (1)

Boreaz
Boreaz

Reputation: 32

This is because you are using double quotes for your not_if statement. Try using curly braces or single quotes instead. Beware of the Powershell logical operator that is using single quotes likewise:

not_if '(Get-ItemProperty HKLM:\\System\\CurrentControlSet\\Control\\Lsa).DisableDomainCreds -eq "1"'

Upvotes: 1

Related Questions