Ansible lookup on file format issue

I have been struggling to use the lookup for vars feature, specifically tried something like:

`

vars:
BUCKET_LIST: “{{ lookup(‘file’, ‘test’) }}”

vars:
BUCKET_LIST: “{{ lookup(‘file’, ‘test’) |to_json }}”

`

Where test is basically just a flat text file, new line separated

What I want to do is to call the variable in a loop so I can use it in another module, e.g. s3

`

  • name: List s3 bucket
    local_action:
    module: s3
    bucket: “{{ item }}”
    mode: list
    with_items: “{{ BUCKET_LIST }}”

`

However from debug I can see that the items are not separated:

`

ok: [localhost] => (item=“test1\ntest2-inputtxt2”) => {
“invocation”: {
▽ “module_args”: {
“msg”: “"test1\ntest2-inputtxt2"”
},
“module_name”: “debug”
},
“item”: “"test1\ntest2-inputtxt2"”,
“msg”: “"test1\ntest2-inputtxt2"”
}

`

Any idea how to properly format with lookup so the item are separated?

BUCKET_LIST: "{{ lookup('file', 'test').split('\n') }}"