# More fun with lists

**URL:** <https://forum.ansible.com/t/more-fun-with-lists/14164>\
**Category:** Ansible Project\
**Created:** [December 16, 2013, 8:52pm UTC](https://forum.ansible.com/t/more-fun-with-lists/14164 "2013-12-16T20:52:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ross\_Becker](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Ross\_Becker](https://forum.ansible.com/u/Ross_Becker)\
**Post date:** [December 16, 2013, 8:52pm UTC](https://forum.ansible.com/t/more-fun-with-lists/14164/1 "2013-12-16T20:52:18Z")

</div>

So, I’ve found another hiccup with lists. I’m trying to set a value through a python “split” call, and then access the individual pieces. I’ve verified that set\_fact does in fact, set a list, because I can use the result for with\_items, and it correctly picks up the individual values, but syntax which works for accessing array elements for a list set as a var, does not work for accessing the array elements when set via set\_fact and python split. Here’s a small playbook which demonstrates the issue:

- hosts: configurator  
user: root  
gather\_facts: False

vars:  
some\_list: [“foo”, “bar”, “baz”]  
ldap\_base\_dn: “[jrbhome.net](http://jrbhome.net)”

tasks:

- name: splittest  
set\_fact: ldap\_domain\_split=“{{ldap\_base\_dn.split(”.“)}}”

- name: retrievetest  
debug: msg=“Item access {{ some\_list[0] }}”

- name: retrievetest  
debug: msg=“Domain part 1 {{ ldap\_domain\_split[0] }}”

- name: retrieveloop  
debug: msg=“Domain part {{item}}”  
with\_items: ldap\_domain\_split

The first debug statement works perfectly, shows ‘foo’ for the value. The with\_items loop works correctly, but the value which comes back from “retrievetest” is ‘[’. I think it’s setting the fact to a string, and accessing characters of the string, rather than correctly picking up that this is an array… but it’s very odd that with\_items works in that case.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [December 16, 2013, 8:58pm UTC](https://forum.ansible.com/t/more-fun-with-lists/14164/2 "2013-12-16T20:58:53Z")

</div>

Yep, I’d expect that.

Set fact is not really intended to store list facts at this time – or at least wasn’t written for them.

I think this should be filed as a feature request, or otherwise someone should take a stab at making this module do a little bit more with complex data types.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [December 16, 2013, 8:59pm UTC](https://forum.ansible.com/t/more-fun-with-lists/14164/3 "2013-12-16T20:59:23Z")

</div>

This may be a bug at some level. But looks like, from my testing, that this is fixed by using something like:

- name: splittest  
set\_fact:  
ldap\_domain\_split: "{{ ldap\_base\_dn.split(‘.’) }}”

when you do a single line set\_fact:

- name: splittest  
set\_fact: ldap\_domain\_split=“{{ldap\_base\_dn.split(”.")}}”

…something doesn’t convey.
