Jinja variable 'dict' object has no attribute

11,229 views
Skip to first unread message

Luke Gracie

unread,
Apr 21, 2014, 10:23:36 AM4/21/14
to salt-...@googlegroups.com
I thought I was getting the hang of salt stack and the pillars, but I just can't get past this error. I'm sure I'm missing something simple and just can't see it. TIA for the assistance.

- Luke

## my structure ##
/srv/salt/top.sls
/srv/salt/users/init.sls
/srv/pillar/top.sls
/srv/pillar/users/init.sls


## pillar and salt top.sls ##
base: 
   '*': 
       - users


## salt/users/init.sls ##
{% for user, userargs in pillar['users'].iteritems() %} 
{{ user }}: 
    user.present: 
      - fullname: {{ userargs['fullname'] }} 
{% endfor %}

## pillar/users/init.sls ##

users:
   gracie:
      fullname: Luke Gracie
      home: /home/gracie
      password: x1
      gid: 500
      groups:
         - wheel


## my error ##

    Data failed to compile:

----------

    Rendering SLS "base:users" failed: Jinja variable 'dict' object has no attribute 'fullname'; line 8

---

[...]

x1


{% for user, userargs in pillar['users'].iteritems() %}

{{ user }}:

 user.present:

  - fullname: {{ userargs['fullname'] }}    <======================

{% endfor %}


Juvenn Woo

unread,
Apr 21, 2014, 10:59:32 AM4/21/14
to salt-...@googlegroups.com

Hi Luke

I guess you're missing a dash before "gracie" in pillar/users/init.sls:

users:
  - gracie:
    fullname: Luke Gracie

since it's an array, is it?

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

W Luke Gracie

unread,
Apr 21, 2014, 12:34:23 PM4/21/14
to salt-...@googlegroups.com
Hello Juvenn,

Thank you for the quick reply. I thought I had tried that before, but with no luck. With that configuration I get this error:

    Data failed to compile:
----------
    Rendering SLS "base:users" failed: Jinja variable 'list' object has no attribute 'iteritems'; line 5
---
{% for user, userargs in pillar['users'].iteritems() %}    <======================
{{ user }}:
 user.present:
  - fullname: {{ userargs['fullname'] }}
{% endfor %}

--
You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/eRx2rTp1NLo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.

Sam Lai

unread,
Apr 21, 2014, 10:14:46 PM4/21/14
to salt-...@googlegroups.com
In salt/users/init.sls, just before the for loop block, add the following -

{{ pillar['users']|pprint }}

... then run: salt servername state.show_highstate

That should force the SLS to render to output, pretty printing
pillar['users'] in the process, which may help shed some light.
Nothing will be executed.

Luke Gracie

unread,
Apr 28, 2014, 12:50:35 PM4/28/14
to salt-...@googlegroups.com
I finally solved this:

I must have had extra hidden data in the mix or something odd like that. I started over with UtahDave's (saltsample_09252012_01) example and made one change at a time and tested as I went. 

This time everything worked fine... 

Thanks!

Luke

Colton Myers

unread,
May 1, 2014, 6:16:22 PM5/1/14
to salt-...@googlegroups.com
This does seem like it should be working.  I would use `salt '*' pillar.items --out=json` to double check that the data is in pillar looks correct, and if it does, then I would maybe make a dummy state that just templates the entire userargs dictionary into the file.  It will fail to compile the highstate, obviously, but if you check the debug logs you'll be able to see what the jinja results were, and see exactly what went wrong with that dictionary.

If you're still having issues, please file an issue on Github.

--
Colton Myers

Luke Gracie

unread,
May 7, 2014, 9:45:39 AM5/7/14
to salt-...@googlegroups.com
so I spent the last week working on my sls files and structure to install everything else I want in a base setup.

I setup the base centos install load the salt-minion and I'm ready to push everything with highstate...

    Data failed to compile:
----------
    Rendering SLS "base:users" failed: Jinja variable 'dict' object has no attribute 'users'; line 2

---

{% for user, args in pillar['users'].iteritems() %}    <======================
{{ user }}:
  user.present:
    - home: {{ args['home'] }}
    - gid: {{ args['gid'] }}
{% if 'password' in args %}


I'm right back where I started.

If I run salt '*' pillar.items I don't see any of my user setup. I should see it, right?

Luke

Colton Myers

unread,
May 13, 2014, 5:55:21 PM5/13/14
to salt-...@googlegroups.com
Yes, you should.  You should post your pillar files (obfuscating any sensitive data, of course) so we can see if we can spot what's going wrong.

--
Colton Myers
Reply all
Reply to author
Forward
0 new messages