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”
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.