FAQ
Hi guys,
I'm trying to define a custom fact on windows puppet agent, I'm using
the version 2.7.14. I made a powershell that checks for the state of a
service and return true or false.
If I execute it on powershell I got this:

PS C:\programdata\PuppetLabs\facter\ext> .\udp_status.ps1
udp_status=true

But If I ran facter I didn't see the facter and value for this custom
fact....

I put the .ps1 file on C:\programdata\PuppetLabs\facter\ext but I can't
see the value for the fact...

What am I doing wrong?....

thank you in advance...

Regards

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To post to this group, send email to puppet-users@googlegroups.com.
To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Search Discussions

  • Mparrad at May 10, 2012 at 8:08 pm
    Hi guys, I realized that If I make the file udp_status.rb and I put on
    D:\Program Files (x86)\Puppet Labs\Puppet\facter\lib\facter, that's where I
    installed puppet from the MSI file, and I use the Powershell script that I
    made, I got the value that I expect when I run facter:

    D:\>facter udp_status
    true

    Now, My question will be: How can I use thi fact on a resource exec, Is
    this possible?, I tried using with onlyif => "$udp_status" but I got
    several errors about convertions and another stuffs...

    What would be the correct way to use a fact on a resource EXEC on ​​windows?

    any help would be appreciated

    best regards

    On Thursday, May 10, 2012 11:40:15 AM UTC-4, mparrad wrote:

    Hi guys,
    I'm trying to define a custom fact on windows puppet agent, I'm using
    the version 2.7.14. I made a powershell that checks for the state of a
    service and return true or false.
    If I execute it on powershell I got this:

    PS C:\programdata\PuppetLabs\facter\ext> .\udp_status.ps1
    udp_status=true

    But If I ran facter I didn't see the facter and value for this custom
    fact....

    I put the .ps1 file on C:\programdata\PuppetLabs\facter\ext but I can't
    see the value for the fact...

    What am I doing wrong?....

    thank you in advance...

    Regards
    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/MQR3kXNa93UJ.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Nan Liu at May 11, 2012 at 12:23 am

    On Thu, May 10, 2012 at 1:08 PM, mparrad wrote:
    Hi guys, I realized that If I make the file udp_status.rb and I put on
    D:\Program Files (x86)\Puppet Labs\Puppet\facter\lib\facter, that's where I
    installed puppet from the MSI file, and I use the Powershell script that I
    made, I got the value that I expect when I run facter:

    D:\>facter udp_status
    true

    Now, My question will be: How can I use thi fact on a resource exec, Is this
    possible?, I tried using with onlyif => "$udp_status" but I got several
    errors about convertions and another stuffs...
    Facts are provided to the master, so in this case simply:

    if $udp_status {
    exec { ... }
    }

    If the fact return false simply don't include the exec in the catalog.

    HTH,

    Nan

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Marco Parra D. at May 14, 2012 at 7:31 pm
    Hi Nan:
    On 10-05-2012 20:22, Nan Liu wrote:
    On Thu, May 10, 2012 at 1:08 PM, mparradwrote:
    Hi guys, I realized that If I make the file udp_status.rb and I put on
    D:\Program Files (x86)\Puppet Labs\Puppet\facter\lib\facter, that's where I
    installed puppet from the MSI file, and I use the Powershell script that I
    made, I got the value that I expect when I run facter:

    D:\>facter udp_status
    true

    Now, My question will be: How can I use thi fact on a resource exec, Is this
    possible?, I tried using with onlyif => "$udp_status" but I got several
    errors about convertions and another stuffs...
    Facts are provided to the master, so in this case simply:

    if $udp_status {
    exec { ... }
    }

    If the fact return false simply don't include the exec in the catalog.

    HTH,

    Nan
    I tested as you said, I put the If statement previous to the resource
    exec using the udp_status fact , and It works perfect..


    Thank you a lot...

    Best Regards

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Jeff McCune at May 11, 2012 at 4:09 am

    On Thu, May 10, 2012 at 1:08 PM, mparrad wrote:

    Hi guys, I realized that If I make the file udp_status.rb and I put on
    D:\Program Files (x86)\Puppet Labs\Puppet\facter\lib\facter, that's where I
    installed puppet from the MSI file, and I use the Powershell script that I
    made, I got the value that I expect when I run facter:
    That's great you were able to work this out. Would you mind pasting the
    copy of udp_status.rb into gist.github.com to share? This will help us
    understand what your goal is.

    D:\>facter udp_status
    true

    Now, My question will be: How can I use thi fact on a resource exec, Is
    this possible?, I tried using with onlyif => "$udp_status" but I got
    several errors about convertions and another stuffs...
    The onlyif parameter of the exec resource is meant to be set to a shell
    command. If the exit status is OK (usually a return code of 0 on unix)
    then the exec resource on the system is considered out of sync with the
    catalog. Puppet executes the command specified with the command parameter
    when the resource is out of sync.

    It's definitely possible to use the fact with an exec resource, or any
    resource Puppet can manage. Since it's a variable you can use it in any
    string in the manifest files. You can also use it in a template with the
    template() function.

    What would be the correct way to use a fact on a resource EXEC on
    ​​windows?

    What are you trying to accomplish? Since you were using onlyif, perhaps
    execute a command only if a udp port is open?

    -Jeff

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
  • Marco Parra D. at May 11, 2012 at 1:08 pm
    Hi Jeff,
    On 11-05-2012 0:08, Jeff McCune wrote:
    On Thu, May 10, 2012 at 1:08 PM, mparrad wrote:

    Hi guys, I realized that If I make the file udp_status.rb and I
    put on D:\Program Files (x86)\Puppet
    Labs\Puppet\facter\lib\facter, that's where I installed puppet
    from the MSI file, and I use the Powershell script that I made, I
    got the value that I expect when I run facter:


    That's great you were able to work this out. Would you mind pasting
    the copy of udp_status.rb into gist.github.com
    <http://gist.github.com> to share? This will help us understand what
    your goal is.

    D:\>facter udp_status
    true
    I try to verify is a service was installed, this is my rb file for the
    fact udp_status.rb:

    Facter.add("udp_status") do
    setcode do

    Facter::Util::Resolution.exec('C:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe
    -ExecutionPolicy remotesigned -File D:\installs\Scripts\check_udp.ps1')
    end
    end

    And my check_udp.ps1 file is:

    Function Check-UDP()
    {
    $Service=Get-Service cscudpprocessor -ComputerName localhost
    if ($Service.status -eq "Running")
    {
    write-host "true"
    }
    else
    {
    Write-host "false"
    }
    }

    Check-UDP
    Now, My question will be: How can I use thi fact on a resource
    exec, Is this possible?, I tried using with onlyif =>
    "$udp_status" but I got several errors about convertions and
    another stuffs...


    The onlyif parameter of the exec resource is meant to be set to a
    shell command. If the exit status is OK (usually a return code of 0
    on unix) then the exec resource on the system is considered out of
    sync with the catalog. Puppet executes the command specified with the
    command parameter when the resource is out of sync.

    It's definitely possible to use the fact with an exec resource, or any
    resource Puppet can manage. Since it's a variable you can use it in
    any string in the manifest files. You can also use it in a template
    with the template() function.

    What would be the correct way to use a fact on a resource EXECon ​
    ​windows?


    What are you trying to accomplish? Since you were using onlyif,
    perhaps execute a command only if a udp port is open?
    I try to make that puppet install the service UDP, if is already
    installed do nothing.... I think I acomplish that making the next
    thing, when the service is installed the next time that puppet agent
    run, I got a error from puppet because the execution form
    installutil.exe returns a 255 code; My idea was originally use fact to
    acomplish that, but I couldn't... this is my resource definition now:

    exec { 'Install-UDP':
    command =>
    'C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\InstallUtil.exe
    /username=DOMAIN\username /password=somepassword /unattended
    d:\\services\\CommonUdpService\\bin\\MyApplication.Common.UDP.exe',
    timeout => 0,
    returns => ['0','255'],
    provider => windows,
    path => ['C:\ProgramData\PuppetLabs\facter\ext'],
    onlyif =>
    'C:\\Windows\\Sysnative\\WindowsPowerShell\\v1.0\\powershell.exe
    -ExecutionPolicy remotesigned -File D:\\installs\\Scripts\\check_udp.ps1',
    }

    My service isn't the Protocol UDP, its only the name of the service....


    Thank you
    -Jeff

    --
    You received this message because you are subscribed to the Google
    Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to
    puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at
    http://groups.google.com/group/puppet-users?hl=en.

    Best Regards..!

    --
    You received this message because you are subscribed to the Google Groups "Puppet Users" group.
    To post to this group, send email to puppet-users@googlegroups.com.
    To unsubscribe from this group, send email to puppet-users+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppuppet-users @
categoriespuppet
postedMay 10, '12 at 3:41p
activeMay 14, '12 at 7:31p
posts6
users3
websitepuppetlabs.com

People

Translate

site design / logo © 2022 Grokbase