csvfile - let the config system do the typecasting (#82263)

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/82658/merge
Herman van Rink 1 year ago committed by GitHub
parent ac110eb012
commit 363c57b311
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
minor_changes:
- csvfile - let the config system do the typecasting (https://github.com/ansible/ansible/pull/82263).

@ -16,7 +16,8 @@ DOCUMENTATION = r"""
options:
col:
description: column to return (0 indexed).
default: "1"
default: 1
type: int
keycol:
description: column to search in (0 indexed).
default: 0
@ -164,7 +165,7 @@ class LookupModule(LookupBase):
for row in creader:
if len(row) and row[keycol] == key:
return row[int(col)]
return row[col]
except Exception as e:
raise AnsibleError("csvfile: %s" % to_native(e))

@ -82,7 +82,19 @@
assert:
that:
- lookup('csvfile', 'notfound file=people.csv delimiter=, col=2') == []
- lookup('csvfile', 'notfound file=people.csv delimiter=, col=2, default=what?') == "what?"
- lookup('csvfile', 'notfound file=people.csv delimiter=, col=2 default=what?') == "what?"
- name: Pass wrong terms value fails parse_kv
set_fact:
people_col_2: '{{ lookup("csvfile", "notfound file=people.csv delimiter=, col=2, default=what?") }}'
ignore_errors: yes
register: people_col_2_r
- name: Check if wrong terms value fails parse_kv
assert:
that:
- people_col_2_r.failed
- "'Invalid type for configuration option' in people_col_2_r.msg"
# NOTE: For historical reasons, this is correct; quotes in the search field must
# be treated literally as if they appear (escaped as required) in the field in the

Loading…
Cancel
Save