2

Ok, I've spent days chasing this around. Is there an issue with puppet agent 3.7.1 x64 on Windows 7 x64 where execs with "unless" don't ever NOT run the command? I've tried doing Batch example:

unless => "C:/ProgramData/chocolatey/choco.exe source list | findstr -i 'chocolatey [Disabled]'",

Powershell and now a compiled AutoIT executable:

exec { 'disablepublicchocolatey':
        command => "C:/ProgramData/chocolatey/choco.exe source disable -n=chocolatey",
        unless  => 'c:/ProgramData/puppetfiles/checkifexists.exe repo "chocolatey [disabled]"',
        require => [Exec['chocolatelyinstall'],File['checkifexists.exe']],
      }

My script returns 1 if it finds the text 'chocolatey [disabled]' in the output of choco source list (the text match is NOT case sensitive)... So... this should NOT run if

c:\TEMP\AutoitScripts\chocolatey>choco source list     
Chocolatey v0.9.9.6   
chocolatey [Disabled] - https://chocolatey.org/api/v2/

but it seem to always run... Is there a bug? Am I just very confused?

4
  • Can you clarify your question? Are you always trying to run the command or do you want it to run whenever puppet is run?
    – AWippler
    May 26 '15 at 16:58
  • What I want to do is NOT run the command if "chocolatey [Disabled]" is in the output of choco source list.
    – jmp242
    May 26 '15 at 17:00
  • have you tried only if? onlyif => 'c:/ProgramData/puppetfiles/checkifexists.exe repo "chocolatey [enabled]"'
    – AWippler
    May 26 '15 at 17:03
  • This is similar to stackoverflow.com/questions/30400186/… May 27 '15 at 18:42
2

To use commands with pipe |, you must use the shell builtins work around with cmd.exe /C:

See the example below:

exec { 'configure_timezone':
  command => "tzutil.exe /s \"${timezone}\"",
  unless  => "cmd.exe /C tzutil.exe /g | findstr /C:\"${timezone}\"",
}
2
  • Well, I ended up not needing to do this as I found a config file I could just manage as a template, which "just works".
    – jmp242
    May 27 '15 at 17:09
  • @jmp242 awesome :) May 27 '15 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.