# Stuck: One or more undefined variables: 'str object' has no attribute 'base'

**URL:** <https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169>\
**Category:** Ansible Project\
**Created:** [September 9, 2014, 11:12pm UTC](https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169 "2014-09-09T23:12:53Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Ansible-ML](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Patrick\_Ansible-ML](https://forum.ansible.com/u/Patrick_Ansible-ML)\
**Post date:** [September 9, 2014, 11:12pm UTC](https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169/1 "2014-09-09T23:12:53Z")

</div>

Hi all,

New to the list. Been playing with Ansible for a few hours and I could use a hand in getting a task going. I've not figured out any of the YAML magic so please excuse the undoubtedly spectacular errors 🙂

Goal: create a task that installs a couple of directories in /home/patrick and /root.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 10, 2014, 1:26pm UTC](https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169/2 "2014-09-10T13:26:11Z")

</div>

Yes, where you are defining “test” some of the items in that list are hash tables that don’t have a value for “base”, which is why you are getting that error.

Easiest would be to set it to empty string when it does not apply.

However, it’s a little weird that it says “str object”, which seems to imply you have, probably in that “dirs” variable file, refined the variable “test” to a list of strings, as opposed to a list of hash elements.

---

<div class="post-metadata">

**Author:** ![Patrick\_Ansible-ML](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Patrick\_Ansible-ML](https://forum.ansible.com/u/Patrick_Ansible-ML)\
**Post date:** [September 10, 2014, 3:46pm UTC](https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169/3 "2014-09-10T15:46:21Z")

</div>

Hi Michael,

Thank you for your feedback.

> Yes, where you are defining "test" some of the items in that list are  
> hash tables that don't have a value for "base", which is why you are  
> getting that error.

Clearly I need to read more about lists, hashes and dicts. Not being a developer, please stand by while I try to wrap my head around them 🙂

> Easiest would be to set it to empty string when it does not apply.

I couldn't figure that out but in the docs I found 'Nested Loops' that seemed promising. For the archives, here's how I got it working:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [September 10, 2014, 9:14pm UTC](https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169/4 "2014-09-10T21:14:01Z")

</div>

short description, list (or array) is as it sounds, simple list of  
items, a dict or a hash is a list that uses an 'name' to locate the  
item

1, 2, 3 \< = simiple list, in python/yaml/json (stuff ansible uses) it  
is normally in brackets mylist= [1,2,3], lists can be referenced by a  
number that describes the position (normally starting by 0) mylist[1]  
would return 2

a dict, hash or associative array is a special list that uses names,  
normally represented with {}  
mydict = { 'one': 1, 'two': 2, 'three', 3}, to access an item you use  
the names: mydict['two'] returns 2.

in yaml starting with a '-' normally indicates a list item  
mylist:  
&nbsp;&nbsp;- 1  
&nbsp;&nbsp;- 2  
&nbsp;&nbsp;- 3

for dicts just ignore the - and add the name  
mydict:  
&nbsp;&nbsp;one: 1  
&nbsp;&nbsp;two: 2  
&nbsp;&nbsp;three: 3

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 11, 2014, 2:23pm UTC](https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169/5 "2014-09-11T14:23:58Z")

</div>

I’d need to see how you defined test previously to know for sure, but it seems like it was a list of strings and that would have been normal I think.

---

<div class="post-metadata">

**Author:** ![Patrick\_Ansible-ML](https://avatars.discourse-cdn.com/v4/letter/p/a88e57/32.png) [@Patrick\_Ansible-ML](https://forum.ansible.com/u/Patrick_Ansible-ML)\
**Post date:** [September 12, 2014, 12:04am UTC](https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169/6 "2014-09-12T00:04:19Z")

</div>

Hi Brian,

> short description, list (or array) is as it sounds, simple list of  
> items, a dict or a hash is a list that uses an 'name' to locate the  
> item

Got it.

> 1, 2, 3 \< = simiple list, in python/yaml/json (stuff ansible uses) it  
> is normally in brackets mylist= [1,2,3], lists can be referenced by a  
> number that describes the position (normally starting by 0) mylist[1]  
> would return 2

Ok.

> a dict, hash or associative array is a special list that uses names,  
> normally represented with {}  
> mydict = { 'one': 1, 'two': 2, 'three', 3}, to access an item you use  
> the names: mydict['two'] returns 2.

Ok.

> in yaml starting with a '-' normally indicates a list item  
> mylist:  
> &nbsp;&nbsp;&nbsp;- 1  
> &nbsp;&nbsp;&nbsp;- 2  
> &nbsp;&nbsp;&nbsp;- 3

Ok.

> for dicts just ignore the - and add the name  
> mydict:  
> &nbsp;&nbsp;&nbsp;one: 1  
> &nbsp;&nbsp;&nbsp;two: 2  
> &nbsp;&nbsp;&nbsp;three: 3

Ok.

That wasn't too bad 🙂 Small addition. In my first few hours with Ansible I needed this one for file copying from src to dst:

mydict:  
&nbsp;&nbsp;&nbsp;- src: file1.txt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dst: /some/where/file\_1.txt

Thank you for your explanation. That was most helpful. For the archives, the Ansible examples on github also provide a ton of enlightening info on how to do things:

[https://github.com/ansible/ansible-examples/tree/master/language\_features](https://github.com/ansible/ansible-examples/tree/master/language_features)

Cheers,  
Patrick

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [September 12, 2014, 12:46am UTC](https://forum.ansible.com/t/stuck-one-or-more-undefined-variables-str-object-has-no-attribute-base/16169/7 "2014-09-12T00:46:17Z")

</div>

Yeah I am overdue to update the language\_features dir, it should be all mostly accurate, but it should be a little better organized - we’ve been focusing on [docs.ansible.com](http://docs.ansible.com) for a long time.

I don’t think it will teach any bad habits though 🙂
