Having trouble using set_fact with with_file

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.

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.

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