Created
February 27, 2014 01:38
-
-
Save justlooks/9242568 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
here is a example | |
i write a state | |
my pillar file | |
# cat /opt/pillar/mytest/iniit.sls | |
192.168.11.15: | |
- adsrv | |
- cookieshow | |
my state file | |
# cat init.sls | |
/tmp/mytest: | |
file.managed: | |
- source: salt://mytest/mytest.sh | |
- user: hdfs | |
- group: hdfs | |
- template: jinja | |
- defaults: | |
projects: | |
{% for i in pillar[grains['ip_interfaces']['bond0'][0]] %} | |
- {{i}} | |
{% endfor %} | |
and my template file | |
# cat mytest.sh | |
{% for project in projects %} | |
# {{project}} - write all messages to hadoop | |
{% endfor %} | |
and i run salt to put file onto 192.168.11.15 ,work fine | |
# salt 'ch15' state.sls mytest | |
ch15: | |
---------- | |
State: - file | |
Name: /tmp/mytest | |
Function: managed | |
Result: True | |
Comment: File /tmp/mytest updated | |
Changes: diff: New file | |
group: hdfs | |
user: hdfs | |
now i comment my state file ,and write another state | |
# cat init.sls | |
#/tmp/mytest: | |
# file.managed: | |
# - source: salt://mytest/mytest.sh | |
# - user: hdfs | |
# - group: hdfs | |
# - template: jinja | |
# - defaults: | |
# projects: | |
#{% for i in pillar[grains['ip_interfaces']['bond0'][0]] %} | |
# - {{i}} | |
#{% endfor %} | |
/tmp/mytest2: | |
file.managed: | |
- source: salt://mytest/mytest2.sh | |
mytest2.sh is a text file not a template file | |
# cat mytest2.sh | |
mytext | |
and i run it put mytest2.sh onto another host 192.168.11.14 ,it get error | |
# salt 'ch14' state.sls mytest | |
ch14: | |
Data failed to compile: | |
---------- | |
Rendering SLS mytest failed, render error: Traceback (most recent call last): | |
File "/usr/lib/python2.6/site-packages/salt/utils/templates.py", line 63, in render_tmpl | |
output = render_str(tmplstr, context, tmplpath) | |
File "/usr/lib/python2.6/site-packages/salt/utils/templates.py", line 116, in render_jinja_tmpl | |
output = jinja_env.from_string(tmplstr).render(**context) | |
File "/usr/lib64/python2.6/site-packages/jinja2/environment.py", line 669, in render | |
return self.environment.handle_exception(exc_info, True) | |
File "<template>", line 9, in top-level template code | |
UndefinedError: 'dict' object has no attribute '192.168.11.14' | |
Traceback (most recent call last): | |
File "/usr/lib/python2.6/site-packages/salt/state.py", line 1904, in render_state | |
rendered_sls=mods | |
File "/usr/lib/python2.6/site-packages/salt/template.py", line 68, in compile_template | |
ret = render(input_data, env, sls, **render_kwargs) | |
File "/usr/lib/python2.6/site-packages/salt/renderers/jinja.py", line 41, in render | |
tmp_data.get('data', 'Unknown render error in jinja renderer') | |
SaltRenderError: Traceback (most recent call last): | |
File "/usr/lib/python2.6/site-packages/salt/utils/templates.py", line 63, in render_tmpl | |
output = render_str(tmplstr, context, tmplpath) | |
File "/usr/lib/python2.6/site-packages/salt/utils/templates.py", line 116, in render_jinja_tmpl | |
output = jinja_env.from_string(tmplstr).render(**context) | |
File "/usr/lib64/python2.6/site-packages/jinja2/environment.py", line 669, in render | |
return self.environment.handle_exception(exc_info, True) | |
File "<template>", line 9, in top-level template code | |
UndefinedError: 'dict' object has no attribute '192.168.11.14' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment