Unable to manage file: Jinja variable 'dict object' has no attribute
Hi,
Currently getting the following error when trying to include pillar data in an xml.j2 file:
file_|-template_xml_|-/opt/play_custom.xml_|-managed": {
"comment": "Unable to manage file: Jinja variable 'dict object' has no attribute 'sid'",
"name": "/opt/play_custom.xml",
Snippet of xml file in question:
<client cvdPort="" evmgrcPort="" registryDirectory="HOME" installDirectory="/opt" clientCertificate="">
<clientEntity clientName="id{{ pillar['sid'] }}" hostName="id{{ pillar['sid'] }}.foo.bar" physClientName="" physHostName="" vcsServiceGroup="">
</clientEntity>
The sls file involved is as follows:
/etc/hosts:
file.append:
- text: |
1.1.1.1 unrelated.hostname.redacted
{{ grains['ip4_interfaces']['eth0'][0] }} id{{ pillar['sid'] }}.foo.bar
- order: 1
..snip..
template_xml:
file.managed:
- name: /opt/play_custom.xml
- source: salt://cv/files/play_custom.xml.j2
- template: jinja
- user: root
- group: root
- mode: 0644
- order: 4
The first instance of the sid pillar data gets included fine, and /etc/hosts correctly displays the data. It's just the second instance in play_custom.xml that throws the error.
Here's the output of salt --versions
Salt Version:
Salt: 2015.8.0-201-g342e0c0
Dependency Versions:
Jinja2: 2.7.2
M2Crypto: 0.21.1
Mako: 0.9.1
PyYAML: 3.10
PyZMQ: 14.0.1
Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
RAET: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.4
ioflo: Not Installed
libnacl: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.3.0
pycrypto: 2.6.1
System Versions:
dist: Ubuntu 14.04 trusty
machine: x86_64
release: 3.13.0-32-generic
system: Ubuntu 14.04 trusty
Any help appreciated.
/cc @Xiol
@zyio, thanks for the report. This looks like a bug to me. Have you experimented with renaming/additional pillar variables?
Hi @jfindlay,
I've tried the following:
Changing the name of the variable in both instances:
pillar='{"foobarbuzz":"12345"}'
Still results in the same error:
Salt (38af573c): 'file_|-template_xml_|-/opt/play_custom.xml_|-managed': Unable to manage file: Jinja variable 'dict object' has no attribute 'foobarbuzz'
Adding an additional variable:
pillar='{"foobarbuzz":"12345","sid":"123456"}'
In that instance, the hosts file was set to use sid and the xml file to use foobarbuzz
Same error again.
Happy to test further things if you have thoughts?
Cheers
Issue can be worked around in the following fashion, as suggested by @Xiol
sls file amendment:
template_xml:
file.managed:
- name: /opt/play_custom.xml
- source: salt://cv/files/play_custom.xml.j2
- template: jinja
- user: root
- group: root
- mode: 0644
- defaults:
wibble: {{ pillar ['sid'] }}
- order: 4
xml file:
<clientEntity clientName="id{{ wibble }}" hostName="id{{ wibble }}.foo.bar" physClientName="" physHostName="" vcsServiceGroup="">
@zyio, thanks for the additional info. I don't have any (more?) thoughts, but I am glad you have found a workaround.
Hi,
This has been tripping me up as well, is this going to be documented and/or fixed at all?
Thanks
I encountered the error message that led me to this issue when provisioning a second saltmaster for https://docs.saltstack.com/en/latest/topics/tutorials/multimaster.html . The problem in my case was that I had failed to copy the files from /srv/pillar onto the new master. Just mentioning it here in case anyone else made the same mistake and finds this issue when searching for the message.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.