# Importing list file ?

**URL:** <https://forum.ansible.com/t/importing-list-file/31105>\
**Category:** Ansible Project\
**Created:** [August 22, 2019, 7:34pm UTC](https://forum.ansible.com/t/importing-list-file/31105 "2019-08-22T19:34:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tuyen\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tuyen\_Nguyen](https://forum.ansible.com/u/Tuyen_Nguyen)\
**Post date:** [August 22, 2019, 7:34pm UTC](https://forum.ansible.com/t/importing-list-file/31105/1 "2019-08-22T19:34:54Z")

</div>

Hi

I am using the win\_updates module and I want to include a list of approved patches in the whitelist option. I have the list of all my approved patches in a file already, and I would like to know if and how I can import this file to use?

As in example, can I import the list somehow to be a variable called patchlist ?

And then in the win\_updates module, I could do

win\_updates:  
category\_name:

- SecurityUpdates
- CriticalUpdates
- UpdatesRollups  
state: installed  
whitelist: {{ patchlist }  
reboot: yes

---

<div class="post-metadata">

**Author:** ![Zolvaring](https://avatars.discourse-cdn.com/v4/letter/z/ce73a5/32.png) [@Zolvaring](https://forum.ansible.com/u/Zolvaring)\
**Post date:** [August 22, 2019, 7:37pm UTC](https://forum.ansible.com/t/importing-list-file/31105/2 "2019-08-22T19:37:10Z")

</div>

I’m not able to test this at the moment, but I think the file lookup is what you want:

Mylist: “{{ lookup(‘file’, ‘/path/to/my/yaml/list’) }}”

---

<div class="post-metadata">

**Author:** ![Tuyen\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tuyen\_Nguyen](https://forum.ansible.com/u/Tuyen_Nguyen)\
**Post date:** [August 26, 2019, 12:47pm UTC](https://forum.ansible.com/t/importing-list-file/31105/3 "2019-08-26T12:47:40Z")

</div>

HI

Thank you for directing me in the right direction!

I did the following and it worked

win\_updates:  
category\_name:

- SecurityUpdates
- CriticalUpdates
- UpdatesRollups  
state: installed  
whitelist:
- “{{lookup(‘file’,‘patchlist.txt’)}}”  
reboot: yes

---

<div class="post-metadata">

**Author:** ![Tuyen\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tuyen\_Nguyen](https://forum.ansible.com/u/Tuyen_Nguyen)\
**Post date:** [August 26, 2019, 12:53pm UTC](https://forum.ansible.com/t/importing-list-file/31105/4 "2019-08-26T12:53:03Z")

</div>

Actually, it didn’t quite work ☹ The task was able to run through but I just realized it was not importing the file in correct as a list for the whitelist.

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [August 26, 2019, 2:15pm UTC](https://forum.ansible.com/t/importing-list-file/31105/5 "2019-08-26T14:15:36Z")

</div>

Use "from\_yaml" filter and take a look what you get

&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_data: "{{ lookup('file','patchlist.txt')|from\_yaml }}"  
&nbsp;&nbsp;&nbsp;&nbsp;- debug:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var: my\_data

Then use "my\_data" in the update. This should be something similar to the  
line below

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;whitelist: "{{ my\_data.\<name\_of\_the\_list\_inside\_patchlist\_txt\> }}"

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![Tuyen\_Nguyen](https://avatars.discourse-cdn.com/v4/letter/t/3ab097/32.png) [@Tuyen\_Nguyen](https://forum.ansible.com/u/Tuyen_Nguyen)\
**Post date:** [August 29, 2019, 5:04pm UTC](https://forum.ansible.com/t/importing-list-file/31105/6 "2019-08-29T17:04:55Z")

</div>

Thank you again. I was able to add it with the |from\_yaml like you suggested

- set\_fact:  
my\_data: “{{lookup(‘file’,‘patchlist.txt’)|from\_yaml}}”

and then in the whitelist option of win\_updates:  
whitelist: “{{my\_data}}”

The only caveat is that I need to make my patchlist.txt file to be in the form of

- patch1
- patch2

instead of it normally being  
patch1  
patch2

Is there an easy way as part of the Ansible playbook or in the lookup function itself to read the normal file and then convert it to having the - automatically? Or should I add a new play in the playbook to add the "- " in front of the file?

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [August 29, 2019, 5:47pm UTC](https://forum.ansible.com/t/importing-list-file/31105/7 "2019-08-29T17:47:10Z")

</div>

If you want to get list of lines try this

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_patch\_list: "{{ my\_patch\_list|default() + [item] }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;loop: "{{ lookup('file','patchlist.txt').splitlines() }}"

Cheers,

&nbsp;&nbsp;-vlado

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [August 29, 2019, 5:55pm UTC](https://forum.ansible.com/t/importing-list-file/31105/8 "2019-08-29T17:55:37Z")

</div>

Actually this is the same. It doesn't make sense do decompose/compose a list.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;my\_patch\_list: "{{ lookup('file','patchlist.txt').splitlines() }}"
