ansible / ansible.builtin / v2.5.11 / lookup / csvfile read data from a TSV or CSV file | "added in version" 1.5 of ansible.builtin" Authors: Jan-Piet Mens (@jpmens) <jpmens(at)gmail.com>ansible.builtin.csvfile (v2.5.11) — lookup
pip
Install with pip install ansible==2.5.11
The csvfile lookup reads the contents of a file in CSV (comma-separated value) format. The lookup looks for the row where the first column matches keyname, and returns the value in the second column, unless a different column is specified.
- name: Match 'Li' on the first column, return the second column (0 based index) debug: msg="The atomic number of Lithium is {{ lookup('csvfile', 'Li file=elements.csv delimiter=,') }}"
- name: msg="Match 'Li' on the first column, but return the 3rd column (columns start counting after the match)" debug: msg="The atomic mass of Lithium is {{ lookup('csvfile', 'Li file=elements.csv delimiter=, col=2') }}"
col: default: '1' description: column to return (0 index). file: default: ansible.csv description: name of the CSV/TSV file to open. default: default: '' description: what to return if the value is not found in the file. encoding: default: utf-8 description: Encoding (character set) of the used CSV file. version_added: '2.1' version_added_collection: ansible.builtin delimiter: default: TAB description: field separator in the file, for a tab you can specify "TAB" or "t".
_raw: description: - value(s) stored in file column