Ansible lookup on file format issue

18 views
Skip to first unread message

Anthony Cheng

unread,
Sep 23, 2016, 3:43:20 PM9/23/16
to Ansible Project
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?

Kai Stian Olstad

unread,
Sep 23, 2016, 4:27:40 PM9/23/16
to ansible...@googlegroups.com
BUCKET_LIST: "{{ lookup('file', 'test').split('\n') }}"

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages