set_fact with single item array gets flattened -- by design?

15 views
Skip to first unread message

Barry Kaplan

unread,
Jun 27, 2016, 7:19:54 AM6/27/16
to Ansible Project
(ansible 2.1)

I have a set_fact like:

    - name: Get plant agent data from consul
      set_fact:
        myfact: "{{ lookup('consul_kv', 'mykey recurse=true') }}"

When the lookup returns an array of size >= 2, 'myfact' is assigned the array value.

But when the lookup returns an array of size == 1, 'myfact' is assigned the single object at index 0 of the array. The result is arrays of size one are flattened into an dict.

Is this by design? Some kind of attempted helpfulness? Its causing all kinds of grief because subsequent uses of this fact can't depend on it being an array of dict or just a simple dict.

Reply all
Reply to author
Forward
0 new messages