Issue #23053 has been updated by John Bollinger.

Corey Osman wrote:
> changing the run_mode.rb file from ~ to ENV['HOME'] seems to fix this issue.


That's a bit more general than the original code, as tilde expansion depends on 
the $HOME environment variable anyway.  On the other hand, it seems a bit of a 
half measure.  Although the $HOME variable is likely to be set in an 
interactive shell, it is not *guaranteed* to be set in that context or any 
other. 

Supposing that a viable solution must work in Ruby 1.8.7 (so you can't use 
Dir.home()), and that it must produce a full, absolute directory name (instead 
of possibly some intermediate form that consumers must interpret a special way, 
such as one containing '~'), I would say the best solution would be this:


    require 'etc'

    class UnixRunMode < RunMode
       def conf_dir
         which_dir("/etc/puppet", "#{Etc.getpwuid.dir}/.puppet")
       end

       def var_dir
         which_dir("/var/lib/puppet", "#{Etc.getpwuid.dir}/.puppet/var")
       end
    end


I am uncertain whether the same thing would apply to Windows.


----------------------------------------
Bug #23053: couldn't find HOME environment -- expanding `~/.puppet' when 
running puppet command as non root
https://projects.puppetlabs.com/issues/23053#change-99613

* Author: Corey Osman
* Status: Unreviewed
* Priority: Normal
* Assignee: 
* Category: 
* Target version: 
* Affected Puppet version: 2.6.0
* Keywords: nonroot
* Branch: 
----------------------------------------
Puppet seems to have an issue when trying to call itself.  This would normally 
work under root permission but when using a non root user it can't seem to find 
its HOME despite the .puppet directory exists.

for the longest time I though this was just my problem but now its easy to 
reproduce.

Below is a simple test you can run to reproduce the issue.  While printing the 
config issue is not something we do, the output is the same no matter what 
puppet command you run.
<pre>
cat > test.pp << EOF
exec{'puppet_test_nonroot':
     path => ['/bin', '/usr/sbin', '/sbin', '/usr/bin'],
     command => 'puppet config print > /tmp/puppetconfig.txt',
     logoutput => true
}
EOF
puppet apply --verbose test.pp
</pre>

You should get the error:

Notice: /Stage[main]//Exec[puppet_test_nonroot]/returns: Error: Could not 
intialize global default settings: couldn't find HOME environment -- expanding 
`~/.puppet'
Error: puppet config print > /tmp/puppetconfig.txt returned 1 instead of one of 
[0]
Error: /Stage[main]//Exec[puppet_test_nonroot]/returns: change from notrun to 0 
failed: puppet config print > /tmp/puppetconfig.txt returned 1 instead of one 
of [0]


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to