Ansible: Convert string to dictionary

Solution 1:

The text is neither valid JSON nor YAML. You'll have to split the lines and read the dictionaries line by line. For example, given the text

    users_str: |
      { name: user1, uid: 5000 }
      { name: user2, uid: 5001 }

the task below

    - set_fact:
        users_list: "{{ users_list|d([]) + [item|from_yaml] }}"
      loop: "{{ users_str.splitlines() }}"

creates the list of dictionaries

  users_list:
  - name: user1
    uid: 5000
  - name: user2
    uid: 5001

The iteration is trivial now

    - debug:
        var: item.name
      loop: "{{ users_list }}"

gives

  item.name: user1
  item.name: user2