# Formatting facts as a variable list to another module

**URL:** <https://forum.ansible.com/t/formatting-facts-as-a-variable-list-to-another-module/36127>\
**Category:** Ansible Project\
**Created:** [December 17, 2021, 2:22pm UTC](https://forum.ansible.com/t/formatting-facts-as-a-variable-list-to-another-module/36127 "2021-12-17T14:22:53Z")\
**Posts on this page:** 1\
**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:** [December 17, 2021, 2:22pm UTC](https://forum.ansible.com/t/formatting-facts-as-a-variable-list-to-another-module/36127/1 "2021-12-17T14:22:53Z")

</div>

I’m trying to use the ansible-freeipa user module to disable a list of users ([https://github.com/freeipa/ansible-freeipa/blob/master/README-user.md](https://github.com/freeipa/ansible-freeipa/blob/master/README-user.md)). The module accepts a list for its users parameter. I can get the list as a fact, but I can’t seem to get it formatted properly for the module.

I wrote a test playbook with a static variable that worked as follows:

vars:  
idmfqdn: [ipaserver.example.com](http://ipaserver.example.com)  
binduser: ‘admin’  
bindpasswd: ‘{{ secure\_ipa\_pass }}’  
disabled\_uids:

- name: test1
- name: test2

tasks:

- name: Disable flagged accounts  
freeipa.ansible\_freeipa.ipauser:  
ipaadmin\_password: “{{ secure\_ipa\_pass }}”  
users: “{{ disabled\_uids }}”  
state: disabled

However, in my real playbook, when i get the list of users to disable, it is in the following format:

TASK [Disable flagged accounts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [[auth1.secure-ose.faa.gov](http://auth1.secure-ose.faa.gov)] =\> {  
“msg”: “[test1]\n”  
}

I get this as follows:

- name: Set Disabled Users fact  
set\_fact:  
disabled\_users: “{{ user\_show.results | json\_query(‘[\*].json.result.result.{uid: uid[0], mail: mail[0], nsaccountlock: nsaccountlock, pwdexp: krbpasswordexpiration[0]. **datetime** }’) | selectattr(‘pwdexp’,‘\<’,cutoff\_date) | selectattr(‘nsaccountlock’, ‘equalto’, False) | list }}”

- name: Get list of UIDs to disable  
set\_fact:  
disabled\_uids: “{{ disabled\_users | map(attribute=‘uid’) | list | to\_yaml }}”

So how can I create the list that conforms to the static example that the module is expecting?

Thanks,  
Harry
