Strange exec behavior on windows

58 views
Skip to first unread message

cko

unread,
Jul 22, 2014, 4:35:01 AM7/22/14
to puppet...@googlegroups.com
Hi everyone,

I am running Puppet 3.6.2 on the affected Windows Server 2008 R2 node.

First of all the manifest that I'm trying to use:

   define static_route ($net,$netmask,$gw) 
   {
      if $::kernel == 'Linux' 
      {
         exec { "$name":
            command  => "route add -net ${net} netmask ${netmask} gw ${gw}",
            path     => "$::path",
            unless   => "route -n | grep -i '${net}\s*${gw}\s*${netmask}'",
         }
      }
      if $::kernel == 'windows' {
         exec { "$name":
            command  => "route ADD ${net} MASK ${netmask} ${gw}",
            path     => "$::path",
            unless   => "cmd /c route PRINT -4 | FINDSTR /r ${net}.*${netmask}.*${gw}",
         }
      }
   }

   # example values
   static_route { 'route01':
      net     => '200.60.80.148',
      netmask => '255.255.255.128',
      gw      => '10.21.10.5',
   }


This enables me to add a static route to Windows and Linux nodes with the same Puppet syntax. On my Linux nodes this works just fine.

But on my Windows node i notice a strange behavior:
  • When I test this manifest with 'puppet agent -t' ,Puppet creates the static route in the first try. When I run 'puppet agent -t' again there are no further changes. (this is the expected behavior)
  • But when the Puppet run gets triggered by the Puppet service (every 30 minutes) it executes the route add command on EVERY following run. (As if the route is not present. The agent sends a report to the Puppet Dashboard that indicates an successfully executed "Exec" resource)

Is there a mistake in my Puppet code? Or is there any other logical explanation for this behavior?






jcbollinger

unread,
Jul 22, 2014, 9:18:21 AM7/22/14
to puppet...@googlegroups.com


Most likely, the 'unless' command is returning a false result every time it is run by the Puppet service.  The difference from when you run puppet manually could be the user context of the run, though I'm not enough of a Windows guy to suggest specifics.


John

Rob Reynolds

unread,
Jul 22, 2014, 12:29:34 PM7/22/14
to puppet...@googlegroups.com
I'd agree that it might be a user permission thing. You may want to try changing the service over to your account and letting it run to see if it does it. If so it could be the default user set on that is SYSTEM and may not have access to that information. A suggestion if you do find it to be that is to define an account for the agent that would be a local administrator on these boxes.
 


John

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/31986cb5-a76b-4a6e-a2f9-d88a5c556db5%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Rob Reynolds
Developer, Puppet Labs

Join us at PuppetConf 2014September 20-24 in San Francisco
Register by July 31st to take advantage of the Early Bird discount save $249!
Reply all
Reply to author
Forward
0 new messages