csvlookups referencing variables

66 views
Skip to first unread message

Nick Wolff

unread,
Sep 22, 2015, 10:52:41 AM9/22/15
to Ansible Project
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 }}"

Brian Coca

unread,
Sep 22, 2015, 10:56:34 AM9/22/15
to Ansible Project
the 2nd one is right, but you need a space:

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



--
Brian Coca

Nick Wolff

unread,
Sep 22, 2015, 12:25:21 PM9/22/15
to Ansible Project
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
 

Nick Wolff

unread,
Oct 14, 2015, 12:53:19 PM10/14/15
to Ansible Project
Still can't figure this out if anyone has any ideas.

Thanks,

Nick Wolff
Reply all
Reply to author
Forward
0 new messages