# Combining several facts into one array

**URL:** <https://forum.ansible.com/t/combining-several-facts-into-one-array/35823>\
**Category:** Ansible Project\
**Created:** [October 5, 2021, 6:28pm UTC](https://forum.ansible.com/t/combining-several-facts-into-one-array/35823 "2021-10-05T18:28:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [October 5, 2021, 6:28pm UTC](https://forum.ansible.com/t/combining-several-facts-into-one-array/35823/1 "2021-10-05T18:28:09Z")

</div>

I’m querying our FreeIPA server for user information. What I need is there UID, GID, and Home directory. I can get those individually, but how can I set a fact that combines all of these items? Here’s the 3 separate facts, I just can’t figure out how to have an array of them:

- name: Set User facts  
set\_fact:  
user\_uid: “{{ user\_find.json.result | json\_query(‘result.uid’) }}”  
user\_gid: “{{ user\_find.json.result | json\_query(‘result.gidnumber’) }}”  
user\_list: “{{ user\_find.json.result | json\_query(‘result.homedirectory’) }}”

Any ideas?  
Harry

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [October 5, 2021, 6:39pm UTC](https://forum.ansible.com/t/combining-several-facts-into-one-array/35823/2 "2021-10-05T18:39:38Z")

</div>

Before we try to do this manually in anisble- are you sure it’s really impossible to craft a radius query that returns all the info you need?

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [October 5, 2021, 6:51pm UTC](https://forum.ansible.com/t/combining-several-facts-into-one-array/35823/3 "2021-10-05T18:51:29Z")

</div>

Our IPA server is really Red Hat IDM, but we’re using the APIs to return all of the user information. I can debug message that info so I know I have it. I just don’t know how to say " I want a list of this, this, and this" so I can use that later. What I’m ultimately looking for is to traverse this list and copy a file to the user’s home folder, and make sure the ownership is right (uid/gid).

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![flowerysong1](https://avatars.discourse-cdn.com/v4/letter/f/ecae2f/32.png) [@flowerysong1](https://forum.ansible.com/u/flowerysong1)\
**Post date:** [October 5, 2021, 10:03pm UTC](https://forum.ansible.com/t/combining-several-facts-into-one-array/35823/4 "2021-10-05T22:03:37Z")

</div>

While the use of json\_query obscures the actual structure that you’re dealing with (and you haven’t provided an example), this looks an awful lot like you’re taking something where you already have all of the information you want in a list, and turning it into three lists. Is there a reason you can’t just use user\_find.json.result.result directly?

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [October 6, 2021, 12:38pm UTC](https://forum.ansible.com/t/combining-several-facts-into-one-array/35823/5 "2021-10-06T12:38:19Z")

</div>

So I’m close. I am able to get the items from the returned list via the IPA API:

- name: Run user\_find from IDM API using previously stored session cookie  
uri:  
url: “https://{{idmfqdn}}/ipa/session/json”  
method: POST  
headers:  
Cookie: “{{ login.set\_cookie }}”  
Referer: “https://{{idmfqdn}}/ipa”  
Content-Type: “application/json”  
Accept: “application/json”  
body\_format: json  
body: “{"method": "user\_find/1","params": [,{"version": "{{ api\_vers }}"}]}”  
register: user\_find

I can print them out and get the info I need:

- name: Print output  
debug:  
msg: “{{ item.uid[0] }}: {{ item.gidnumber[0] }}: {{ item.homedirectory[0] }}”  
with\_items: “{{ user\_find.json.result.result| }}”

However, in my other thread about removing items from the list, I’m trying the suggestion as follows:

- name: Print output  
debug:  
msg: “{{ item.uid[0] }}: {{ item.gidnumber[0] }}: {{ item.homedirectory[0] }}”  
loop: “{{ user\_find.json.result.result|difference(deny) }}”

vars:  
deny: [“/home/admin”,“/home/test”]

This gives me the following validation error:

ERROR! conflicting action statements: debug, deny

I won’t be using debug in the final version of the playbook, so since I know that I can get the info I need, should I just move onto that? Or is there a way to get debug and deny to coexist to I can be SURE I’m getting what I need first?

Thanks,  
Harry

---

<div class="post-metadata">

**Author:** ![Sandip\_Bhattacharya](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@Sandip\_Bhattacharya](https://forum.ansible.com/u/Sandip_Bhattacharya)\
**Post date:** [October 6, 2021, 2:51pm UTC](https://forum.ansible.com/t/combining-several-facts-into-one-array/35823/6 "2021-10-06T14:51:04Z")

</div>

'deny' is wrongly indented. It is a variable. Should be indented under 'vars'.

---

<div class="post-metadata">

**Author:** ![harry\_devine](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/harry_devine/32/5293_2.png) [@harry\_devine](https://forum.ansible.com/u/harry_devine)\
**Post date:** [October 6, 2021, 6:19pm UTC](https://forum.ansible.com/t/combining-several-facts-into-one-array/35823/7 "2021-10-06T18:19:03Z")

</div>

I wanted to let you know that I got this working. I looped through the users list that was generated and skipped over the folders I didn’t need by using:

when: item.homedirectory[0] not in [“/home/admin”, “/home/test2”]

I also referenced the UID and GID in a similar manner (item.uid[0] and item.gidnumber[0]) and was able to use the information I needed to complete the task.

Thanks for the tips!  
Harry
