Hi everybody, I''m trying to write a custom fact that gets the IP Address of any given NIC if it matches a specific IP range. On Linux i use this (works fine) Facter.add("ip_foo") do setcode do Facter::Util::Resolution.exec("/sbin/ifconfig | /bin/grep ''192.168.20[567].'' | /bin/awk ''{ print $2 }'' | /bin/cut -d'':'' -f2") end end Now my Windows Version: Facter.add("ip_foo_windows") do confine :operatingsystem => :windows setcode do Facter::Util::Resolution.exec("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | FINDSTR 192.168.20[567]") end end When i run the command C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | FINDSTR 192.168.20[567] on the box it works perfectly fine. It returns the value that i need. But it seems that puppet doesn''t get that value into the fact. -- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/65472ec1-fe7d-4a83-a144-9534419c78e3%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Josh Cooper
2013-Oct-29 14:30 UTC
Re: [Puppet Users] Custom Windows Fact (match ipaddress)
On Tuesday, October 29, 2013, cko wrote:> Hi everybody, > > I''m trying to write a custom fact that gets the IP Address of any given > NIC if it matches a specific IP range. > > On Linux i use this (works fine) > > Facter.add("ip_foo") do > setcode do > Facter::Util::Resolution.exec("/sbin/ifconfig | /bin/grep > ''192.168.20[567].'' | /bin/awk ''{ print $2 }'' | /bin/cut -d'':'' -f2") > end > end > > Now my Windows Version: > > Facter.add("ip_foo_windows") do > confine :operatingsystem => :windows > setcode do > > Facter::Util::Resolution.exec("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe > ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | > FINDSTR 192.168.20[567]") > end > end >Since you''ve double quoted the string you need to escape the backslashes, eg "C:\\Windows\\...> > > When i run the command C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe > ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | > FINDSTR 192.168.20[567] on the box it works perfectly fine. It returns the > value that i need. > > But it seems that puppet doesn''t get that value into the fact. > > > -- > 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+unsubscribe@googlegroups.com <javascript:_e({}, > ''cvml'', ''puppet-users%2Bunsubscribe@googlegroups.com'');>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/65472ec1-fe7d-4a83-a144-9534419c78e3%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. >Josh -- Josh Cooper Developer, Puppet Labs -- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CA%2Bu97uncpMRX6UykTBG5cPnWNG3n9QLm_QVUj5zBjpZmC45U4A%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
Still no effect. Facter::Util::Resolution.exec("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | FINDSTR 192.168.20[567]") Is there anything else i need to escape? On Tuesday, October 29, 2013 3:07:12 PM UTC+1, cko wrote:> > Hi everybody, > > I''m trying to write a custom fact that gets the IP Address of any given > NIC if it matches a specific IP range. > > On Linux i use this (works fine) > > Facter.add("ip_foo") do > setcode do > Facter::Util::Resolution.exec("/sbin/ifconfig | /bin/grep > ''192.168.20[567].'' | /bin/awk ''{ print $2 }'' | /bin/cut -d'':'' -f2") > end > end > > Now my Windows Version: > > Facter.add("ip_foo_windows") do > confine :operatingsystem => :windows > setcode do > > Facter::Util::Resolution.exec("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe > ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | > FINDSTR 192.168.20[567]") > end > end > > > When i run the command C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe > ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | > FINDSTR 192.168.20[567] on the box it works perfectly fine. It returns the > value that i need. > > But it seems that puppet doesn''t get that value into the fact. > > >-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/f0fbe47f-5bc0-4fc3-bc2a-5eb8d6cad367%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Josh Cooper
2013-Oct-30 15:23 UTC
Re: [Puppet Users] Custom Windows Fact (match ipaddress)
The second issue is that findstr is a shell builtin, so you have wrap the entire command in: cmd.exe /c <original command> You may have to quote the original command and adjust the interior quotes accordingly. Josh On Wednesday, October 30, 2013, cko wrote:> Still no effect. > > > Facter::Util::Resolution.exec("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe > ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | > FINDSTR 192.168.20[567]") > > Is there anything else i need to escape? > > > > > On Tuesday, October 29, 2013 3:07:12 PM UTC+1, cko wrote: >> >> Hi everybody, >> >> I''m trying to write a custom fact that gets the IP Address of any given >> NIC if it matches a specific IP range. >> >> On Linux i use this (works fine) >> >> Facter.add("ip_foo") do >> setcode do >> Facter::Util::Resolution.exec(**"/sbin/ifconfig | /bin/grep >> ''192.168.20[567].'' | /bin/awk ''{ print $2 }'' | /bin/cut -d'':'' -f2") >> end >> end >> >> Now my Windows Version: >> >> Facter.add("ip_foo_windows") do >> confine :operatingsystem => :windows >> setcode do >> Facter::Util::Resolution.exec(**"C:\Windows\System32\** >> WindowsPowerShell\v1.0\**powershell.exe ipconfig | Select-String >> -pattern ''192.168.20[567]'' | %{$_.line.split()} | FINDSTR 192.168.20[567]") >> end >> end >> >> >> When i run the command C:\Windows\System32\**WindowsPowerShell\v1.0\**powershell.exe >> ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | >> FINDSTR 192.168.20[567] on the box it works perfectly fine. It returns the >> value that i need. >> >> But it seems that puppet doesn''t get that value into the fact. >> >> >> -- > 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+unsubscribe@googlegroups.com <javascript:_e({}, > ''cvml'', ''puppet-users%2Bunsubscribe@googlegroups.com'');>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/puppet-users/f0fbe47f-5bc0-4fc3-bc2a-5eb8d6cad367%40googlegroups.com > . > For more options, visit https://groups.google.com/groups/opt_out. >-- Josh Cooper Developer, Puppet Labs -- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CA%2Bu97umXqfg0sxcDx2mdnJsdA1PjP7sEJwOOXgcu_EiqL1BrtQ%40mail.gmail.com. For more options, visit https://groups.google.com/groups/opt_out.
I still can''t get it to work: Facter::Util::Resolution.exec("C:\\Windows\\System32\\cmd.exe /c ''C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | FINDSTR 192.168.20[567]''") On Wednesday, October 30, 2013 4:23:45 PM UTC+1, Josh Cooper wrote:> > The second issue is that findstr is a shell builtin, so you have wrap the > entire command in: > > cmd.exe /c <original command> > > You may have to quote the original command and adjust the interior quotes > accordingly. > > Josh > > On Wednesday, October 30, 2013, cko wrote: > >> Still no effect. >> >> >> Facter::Util::Resolution.exec("C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe >> ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | >> FINDSTR 192.168.20[567]") >> >> Is there anything else i need to escape? >> >> >> >> >> On Tuesday, October 29, 2013 3:07:12 PM UTC+1, cko wrote: >>> >>> Hi everybody, >>> >>> I''m trying to write a custom fact that gets the IP Address of any given >>> NIC if it matches a specific IP range. >>> >>> On Linux i use this (works fine) >>> >>> Facter.add("ip_foo") do >>> setcode do >>> Facter::Util::Resolution.exec("/sbin/ifconfig | /bin/grep >>> ''192.168.20[567].'' | /bin/awk ''{ print $2 }'' | /bin/cut -d'':'' -f2") >>> end >>> end >>> >>> Now my Windows Version: >>> >>> Facter.add("ip_foo_windows") do >>> confine :operatingsystem => :windows >>> setcode do >>> Facter::Util::Resolution.exec("C:\Windows\System32\ >>> WindowsPowerShell\v1.0\powershell.exe ipconfig | Select-String -pattern >>> ''192.168.20[567]'' | %{$_.line.split()} | FINDSTR 192.168.20[567]") >>> end >>> end >>> >>> >>> When i run the command C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe >>> ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | >>> FINDSTR 192.168.20[567] on the box it works perfectly fine. It returns the >>> value that i need. >>> >>> But it seems that puppet doesn''t get that value into the fact. >>> >>> >>> -- >> 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+unsubscribe@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/puppet-users/f0fbe47f-5bc0-4fc3-bc2a-5eb8d6cad367%40googlegroups.com >> . >> For more options, visit https://groups.google.com/groups/opt_out. >> > > > -- > Josh Cooper > Developer, Puppet Labs > >-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/4e1302b5-1fdb-4a72-b696-9df65f586460%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
giovanni possemato
2013-Nov-12 11:29 UTC
[Puppet Users] Re: Custom Windows Fact (match ipaddress)
hi all, try using the sysnative instead of System32 The File System Redirector<http://msdn.microsoft.com/en-us/library/aa384187(v=vs.85).aspx> will> silently redirect all file system access to%windir%\system32 to > %windir%\SysWOW64 instead. This can be an issue when trying to manage > files in the system directory, e.g., IIS configuration files. In order to > prevent redirection, you can use the sysnative alias, e.g.C:\Windows\sysnative\inetsrv\config\application > Host.config.https://ask.puppetlabs.com/question/4016/sysprep-on-puppet/ Il giorno martedì 29 ottobre 2013 15:07:12 UTC+1, cko ha scritto:> > Hi everybody, > > I''m trying to write a custom fact that gets the IP Address of any given > NIC if it matches a specific IP range. > > On Linux i use this (works fine) > > Facter.add("ip_foo") do > setcode do > Facter::Util::Resolution.exec("/sbin/ifconfig | /bin/grep > ''192.168.20[567].'' | /bin/awk ''{ print $2 }'' | /bin/cut -d'':'' -f2") > end > end > > Now my Windows Version: > > Facter.add("ip_foo_windows") do > confine :operatingsystem => :windows > setcode do > > Facter::Util::Resolution.exec("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe > ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | > FINDSTR 192.168.20[567]") > end > end > > > When i run the command C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe > ipconfig | Select-String -pattern ''192.168.20[567]'' | %{$_.line.split()} | > FINDSTR 192.168.20[567] on the box it works perfectly fine. It returns the > value that i need. > > But it seems that puppet doesn''t get that value into the fact. > > >-- 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+unsubscribe@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2113b2e2-6eca-4c24-8e6e-8d2648d77a83%40googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.