# Having trouble using set\_fact with with\_file

**URL:** <https://forum.ansible.com/t/having-trouble-using-set-fact-with-with-file/13414>\
**Category:** Ansible Project\
**Created:** [September 3, 2013, 9:30pm UTC](https://forum.ansible.com/t/having-trouble-using-set-fact-with-with-file/13414 "2013-09-03T21:30:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Hawley](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@Tom\_Hawley](https://forum.ansible.com/u/Tom_Hawley)\
**Post date:** [September 3, 2013, 9:30pm UTC](https://forum.ansible.com/t/having-trouble-using-set-fact-with-with-file/13414/1 "2013-09-03T21:30:55Z")

</div>

Hello,

I am trying to set a fact from the content of a file using “set\_fact” but it fails if I use “with\_file” in the same task block of a playbook. I have created a simple example playbook to show the problem.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 3, 2013, 10:43pm UTC](https://forum.ansible.com/t/having-trouble-using-set-fact-with-with-file/13414/2 "2013-09-03T22:43:24Z")

</div>

The “with” constructs return lists. Instead do:

set\_fact: my\_new\_fact={{ lookup(‘file’, ‘~/my\_secret\_file’) }}

Though it’s probably easier to just use vars\_files, depending on your usage, which also looks a lot cleaner.

---

<div class="post-metadata">

**Author:** ![Tom\_Hawley](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@Tom\_Hawley](https://forum.ansible.com/u/Tom_Hawley)\
**Post date:** [September 3, 2013, 11:42pm UTC](https://forum.ansible.com/t/having-trouble-using-set-fact-with-with-file/13414/3 "2013-09-03T23:42:32Z")

</div>

Thank you for the quick reply - my playbook is now working!

I’ll look into switching to vars\_files as it is a bit ugly.

Tom
