Windows minion custom grains 'dict object' has no attribute
Hi,
I have a custom grain module in the _grains folder in the files_root of the master. After executing a highstate on a windows minion, I see, that the grain module is in the cache directory. The highstate runs fine, and not uses the grain module. But when calling a single state, which uses the grain, i get the following error:
Data failed to compile:
----------
Rendering SLS "base:win.git.checkout" failed: Jinja variable 'dict object' has no attribute 'prodenv_code_is_write_protected'; line 1
---
{% if not grains['prodenv_code_is_write_protected'] %} <======================
get-certificate:
file.managed:
- name: 'c:\Users\Administrator\.ssh\github_teamcity_rsa'
- source: salt://secrets/ssh/github_teamcity_rsa
- makedirs: True
[...]
---
even after executing a sync_all, still the same error occures.
grain module:
def prodenv_code_is_write_protected():
"""if code is read only or mapped through vagrant into system return True"""
isVagrantMapped = False
testfilePath = os.path.join(_prodenv_code_path(), "writetestfile.txt")
try:
with open(testfilePath, "w") as f:
f.write("writetest")
os.unlink(testfilePath)
isVagrantMapped = _prodenv_runs_in_vagrant()
except IOError as e:
if e.errno == 30:
isVagrantMapped = True
return {"prodenv_code_is_write_protected": isVagrantMapped}
state file:
{% if not grains['prodenv_code_is_write_protected'] %}
get-certificate:
file.managed:
- name: 'c:\Users\Administrator\.ssh\github_teamcity_rsa'
- source: salt://secrets/ssh/github_teamcity_rsa
- makedirs: True
get-ssh-config:
file.managed:
- name: 'c:\Users\Administrator\.ssh\config'
- source: salt://win/ssh/config
- makedirs: True
{% endif %}
Windows Server 2008 R2 Minion:
Salt: 2014.1.7
Python: 2.7.5 (default, May 15 2013, 22:44:16) [MSC v.1500 64 bit (AMD64)]
Jinja2: 2.7.1
M2Crypto: 0.21.1
msgpack-python: 0.4.2
msgpack-pure: Not Installed
pycrypto: 2.6
PyYAML: 3.11
PyZMQ: 14.1.1
ZMQ: 4.0.4
Ubuntu Server 14.04 LTS Master:
Salt: 2014.1.7
Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
Jinja2: 2.7.2
M2Crypto: 0.21.1
msgpack-python: 0.3.0
msgpack-pure: Not Installed
pycrypto: 2.6.1
PyYAML: 3.10
PyZMQ: 14.0.1
ZMQ: 4.0.4
I just saw in the log file, that a stacktrace occured while importing the grain:
Traceback (most recent call last):
File "salt/loader.py", line 707, in gen_functions
File "c:\salt\var\cache\salt\minion\extmods\grains\prodenv_info.py", line 17, in <module>
import importlib
ImportError: No module named importlib
This explains it, but why salt does not have this module??
Can you run a python interpreter and run import importlib in the python interpreter? Basically, you must make sure that any required modules are available on the PYTHONPATH of the copy of python which is running salt. Most commonly, people run into problems where salt is running on one version of python, but they also have a second version of python installed, and that's where they installed the module. You must make sure that you installed the module for the same version of python that is running salt.
Yes, I am able to import importlib using the python interpreter. But i thought that on Windows minions, salt has its own python interpreter built in. So maybe this one is missing importlib.
Yeah, it's possible it hasn't been included during the build process On Jul 17, 2014 12:22 AM, "Béla Wäckerlig" [email protected] wrote:
Yes, I am able to import importlib using the python interpreter. But i thought that on Windows minions, salt has its own python interpreter built in. So maybe this one is missing importlib.
— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/14237#issuecomment-49262660.
can i include it after afterwards, or do i have to wait for a new release /if it is planed to include it in the future)? Sorry, I'm not really familiar with python :)
I'm not sure if it's possible to add it after the build since we use bbfreeze/esky to compile all the deps.
Is importlib necessary for your grain?
If so, I could put together an installer for you that includes it. I might be able to get that tomorrow On Jul 17, 2014 1:17 AM, "Béla Wäckerlig" [email protected] wrote:
can i include it after afterwards, or do i have to wait for a new release /if it is planed to include it in the future)? Sorry, I'm not really familiar with python :)
— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/14237#issuecomment-49266790.
yes, i need it to read configs out of a python file. It would be really nice to have a new installer :)
@UtahDave haven't we had good luck just throwing .egg files into the salt installation?
@UtahDave @basepi I would reckon this can be closed as resolved since 2015.5.3 as we use a proper Python installation now.
Thanks!