csvlookups referencing variables

Hello all,

I’m trying to do a csvlookup that references a variable so I can dynamically choose which line of the file. I tried the first two thinks to do the lookup with name only the third directly referencing the name works

  • hosts: “{{ target }}”
    vars:
    name : “REALUSER”
    uid : “{{ lookup(‘csvfile’, ''name delimiter=: file=/etc/passwd col=2 ') }}”
    gid : ‘{{ lookup(“csvfile”, name + “file=/etc/passwd col=3 delimiter=:”) }}’
    comment : ‘{{ lookup(“csvfile”, “REALUSER file=/etc/passwd delimiter=: col=4”) }}’
    tasks:
  • debug: msg=“The uid is {{ uid }} and the name is {{name}} and the gid is {{ gid }}”

the 2nd one is right, but you need a space:

'{{ lookup("csvfile", name + " file=/etc/passwd col=3 delimiter=:") }}'

If I do that I get back

[WARNING]: non fatal error while trying to template play variables: Failed to
template {{ lookup(“csvfile”, name + " file=/etc/passwd col=3 delimiter=:")
}}: csvfile: “delimiter” must be an 1-character string

Still can’t figure this out if anyone has any ideas.

Thanks,

Nick Wolff