"problem" with windows client

31 views
Skip to first unread message

Gianmarco Carrieri

unread,
Dec 10, 2014, 4:35:32 AM12/10/14
to puppet...@googlegroups.com
Hi all,

sorry if this is a repost, i need to use a windows env in the configuration of puppet.

this is a piece of my conf:

        file { "Mozilla":
                ensure => "directory",
                recurse => "true",
                path => "%appdata%",
                purge => true,
                force => true,
                source => "puppet:///modules/winpc/Firefox_Profiles",
         #       source_permissions => 'ignore'
        }

how i can use the env variable %appdata%

thanks in advance and sorry for my english. :)

Josh Cooper

unread,
Dec 12, 2014, 1:04:01 PM12/12/14
to puppet...@googlegroups.com
You'll need to create a custom fact that contains the path. This can be done in ruby like:

  Facter.add(:local_appdata) do
    confine :kernel => :windows
    setcode do
      require 'win32/dir'
      Dir::LOCAL_APPDATA
  end 

or whichever well-known folder you're looking for. The constants are defined in the win32-dir gem[1]. Then in your manifest, you would need to do:

  path => $::local_appdata

Note that you need specify the complete path for the process, not just a single directory. For example, if you apply the following resource:

  exec { 'c:\windows\sysnative\cmd.exe /c echo %PATH%':
    path => 'c:\windows\system32',
    logoutput => true
  }

You'll see that PATH for the process is only 'c:\windows\system32':

  C:\>puppet apply c:\path.pp
  ...
  Notice: /Stage[main]/Main/Exec[c:\windows\sysnative\cmd.exe /c echo %PATH%]/returns: c:\windows\system32

So you'll want to do something like:

  path => $::local_appdata;$path

where `$path` refers to the built-in fact[2].


thanks in advance and sorry for my english. :)

--
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/3530a4eb-8277-4841-97ac-16dcdfb1d4ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Josh


--
Josh Cooper
Developer, Puppet Labs

Join us at PuppetConf 2015, October 5-9 in Portland, OR - http://2015.puppetconf.com.  
Register early to save 40%!

Felix Frank

unread,
Dec 12, 2014, 4:49:33 PM12/12/14
to puppet...@googlegroups.com
On 12/12/2014 07:03 PM, Josh Cooper wrote:
> The constants are defined in the win32-dir gem[1].
>

Aweseome!

> path => $::local_appdata;$path

Wait, shouldn't this be

path => [ $local_appdata, $path ]

The semicolon would end the resource declaration I believe.

Cheers,
Felix

Josh Cooper

unread,
Dec 12, 2014, 5:01:27 PM12/12/14
to puppet...@googlegroups.com
Actually it supports both! So either an array or a string whose components are delimited with the platform-specific separator: https://github.com/puppetlabs/puppet/blob/master/lib/puppet/type/exec.rb#L181-L192

An array is probably preferable since puppet will just do-the-right-thing for that platform.


Cheers,
Felix


--
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.

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

Josh

Felix Frank

unread,
Dec 12, 2014, 6:33:33 PM12/12/14
to puppet...@googlegroups.com
On 12/12/2014 11:01 PM, Josh Cooper wrote:
path => [ $local_appdata, $path ]

The semicolon would end the resource declaration I believe.

Actually it supports both! So either an array or a string whose components are delimited with the platform-specific separator: https://github.com/puppetlabs/puppet/blob/master/lib/puppet/type/exec.rb#L181-L192

Ah, I see. The native form should be quoted in this case, though. Otherwise, the parser will misinterpret the semicolon.
Reply all
Reply to author
Forward
0 new messages