Saltstack Mac OS X and Homebrew
I see that there is a brew module which successfully lets me install packages via the command line. However using states w/ Mac OS X and Homebrew seems to be broken. Is this a known issue?
I looked at the code and I see the brew module doesn't have a refresh_db method. I haven't looked at homebrew code, but the man page leads me to believe it doesn't really use a package db. Shouldn't state.py skip the refresh_db call for Mac OSX and homebrew?
sudo salt '*' pkg.install tmux
Password:
32.11.168.192.in-addr.arpa:
----------
libevent:
----------
new:
2.0.21
old:
tmux:
----------
new:
1.8
old:
But if I create a simple state
cat /srv/salt/tmux/init.sls
tmux:
pkg:
- installed
running a state.highstate throws errors.
sudo salt '*' state.highstate test=True
32.11.168.192.in-addr.arpa:
----------
State: - pkg
Name: tmux
Function: installed
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/salt/state.py", line 1278, in call
*cdata['args'], **cdata['kwargs'])
File "/usr/local/lib/python2.7/site-packages/salt/states/pkg.py", line 423, in installed
__salt__['pkg.refresh_db']()
KeyError: 'pkg.refresh_db'
Changes:
----------
State: - pkg
Name: zsh
Function: installed
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/salt/state.py", line 1278, in call
*cdata['args'], **cdata['kwargs'])
File "/usr/local/lib/python2.7/site-packages/salt/states/pkg.py", line 423, in installed
__salt__['pkg.refresh_db']()
KeyError: 'pkg.refresh_db'
Changes:
Summary
------------
Succeeded: 0
Failed: 2
------------
Total: 2
Yep, we just need to bring that module in line with the other pkg modules, then it should start working with the pkg state. Thanks for the report.
is there any progress on this issue? without the possibility to install packages through states, manage mac os x through salt is a little bit pointless
There has been no progress on this issue to my knowledge. We still want to get the brew module in line with the rest of the pkg modules so that it will be usable in states, but we just haven't had the bandwidth to implement it yet.
Looks like this is in master: https://github.com/saltstack/salt/commit/7ad966b1fa767ba6fffdb3897c80a4b23ce905fc
Works for me when I include as a custom module.
just modified the module, compiled it and it worked. Thank you very mouch!!
Note that if you are using this as a custom module, you can run into an error that looks like this:
State: - pkg
Name: MyPackage
Function: installed
Result: False
Comment: An exception occurred in this state: Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/salt/state.py", line 1315, in call
*cdata['args'], **cdata['kwargs'])
File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/salt/states/pkg.py", line 468, in installed
**kwargs)
File "/var/cache/salt/minion/extmods/modules/brew.py", line 319, in install
return salt.utils.compare_dicts(old, new)
AttributeError: 'module' object has no attribute 'compare_dicts'
This is because the new brew module uses a new version of the salt.utils module.
I hacked this up by pulling out the compare_dict function (it is static and very simple) into a file in _modules I called temp_utils.py.
The diff of the brew.py in that directory is as follows:
< import temp_utils
196c195
< return temp_utils.compare_dicts(old, new)
---
> return salt.utils.compare_dicts(old, new)
320c319
< return temp_utils.compare_dicts(old, new)
---
> return salt.utils.compare_dicts(old, new)
This is not a new bug or anything- the next time there is a release of saltstack this will not be an issue.
Looks like this is also in 2014.1 branch and so will be in the 2014.1.0 release (very soon!).