Question

  • os: MacOS
  • osarch: x86_64
  • osrelease: 10.9
  • path: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

$ salt --versions-report

           Salt: 0.17.2
         Python: 2.7.6 (default, Nov 19 2013, 02:02:54)
         Jinja2: 2.7.1
       M2Crypto: 0.21.1
 msgpack-python: 0.4.0
   msgpack-pure: Not Installed
       pycrypto: 2.6.1
         PyYAML: 3.10
          PyZMQ: 14.0.0
            ZMQ: 3.2.4

$ sudo salt '*' pkg.list_pkgs

MacBook-Pro.local:
    ----------
        from:
        /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in,/usr/local/Library/Homebrew/global.rb:25:in,/usr/local/Library/Homebrew/global.rb:44,/usr/local/Library/brew.rb:17,/usr/local/Library/brew.rb:17:in
    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in:
        `expand_path':

$ sudo salt '*' pkg.list_upgrades

MacBook-Pro.local:
    - /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in `expand_path': couldn't find HOME environment -- expanding `~/Library/Caches/Homebrew' (ArgumentError)
    -   from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/pathname.rb:853:in `expand_path'
    -   from /usr/local/Library/Homebrew/global.rb:25:in `cache'
    -   from /usr/local/Library/Homebrew/global.rb:44
    -   from /usr/local/Library/brew.rb:17:in `require'
    -   from /usr/local/Library/brew.rb:17

but running brew from the command line is working fine:

$ brew list --versions

cairo 1.12.16
ccze 0.2.1
cmake 2.8.12.1
curl 7.33.0
fontconfig 2.11.0

$ brew outdated

freetype (2.5.0.1 < 2.5.1)
imagemagick (6.8.7-0 < 6.8.7-7)
libpng (1.5.14 < 1.5.17)
passenger (4.0.24 < 4.0.26)
pixman (0.32.2 < 0.32.4)
zeromq (3.2.4 < 4.0.3)

I suspect that it caused by a different versions of Ruby:

$ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin13.0]

$(which ruby) -v
ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]

$ brew doctor

Your system is ready to brew.

Try to expand from the command line still works:

$ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -ve 'p ENV["HOME"]'
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin13.0]
"/Users/quanta"

$ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -ve 'p File.expand_path("~")'
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin13.0]
"/Users/quanta"
Was it helpful?

Solution

Problem solved by manually defining ENV['HOME'] in the /usr/local/Library/brew.rb file:

ENV['HOME'] = "/Users/quanta"

$ sudo salt '*' pkg.list_upgrades

MacBook-Pro.local:
    - freetype
    - imagemagick
    - libpng
    - mysql
    - passenger
    - pixman
    - redis
    - zeromq

but my question still stand: why can't the Salt the HOME environment variable?


UPDATE Sun Dec 8 15:26:03 ICT 2013

Since salt-minion is started via launchctl:

com.saltstack.minion.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>com.saltstack.minion</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/local/bin/salt-minion</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

a question comes up to my mind: how to specify an environment variable in a launchd script? And the answer is:

man launchd.plist:

EnvironmentVariables <dictionary of strings>
     This optional key is used to specify additional environmental variables to be set before running the job.

so I added the following into the plist file:

<dict>
  <key>HOME</key>
  <string>/Users/quanta</string>
</dict>

then restarted the minion service, and now it's working fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top