[Puppet Users] Re: Strange exec behavior on windows

2014-07-22 Thread jcbollinger


On Tuesday, July 22, 2014 3:35:01 AM UTC-5, cko wrote:

 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?



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

-- 
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+unsubscr...@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.


Re: [Puppet Users] Re: Strange exec behavior on windows

2014-07-22 Thread Rob Reynolds
On Tue, Jul 22, 2014 at 6:18 AM, jcbollinger john.bollin...@stjude.org
wrote:



 On Tuesday, July 22, 2014 3:35:01 AM UTC-5, cko wrote:

 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?



 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.


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+unsubscr...@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
 https://groups.google.com/d/msgid/puppet-users/31986cb5-a76b-4a6e-a2f9-d88a5c556db5%40googlegroups.com?utm_medium=emailutm_source=footer
 .

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




-- 
Rob Reynolds
Developer, Puppet Labs

*Join us at PuppetConf 2014 http://www.puppetconf.com/, September
20-24 in San Francisco*
*Register by July 31st to take advantage of the Early Bird discount
https://puppetconf2014.eventbrite.com/?discount=EarlyBird **--**save $249!*

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAMJiBK63-eY7Qh8CbTcPv7AtvO6kanm_k0NXnQR9o-EYTRHsfg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.