Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
d0f8df4b
Commit
d0f8df4b
authored
Feb 26, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10079 from lorin/csv-lookup-doc
Add docs for csvfile lookup
parents
893f1326
6a701247
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
docsite/rst/playbooks_lookups.rst
+48
-0
No files found.
docsite/rst/playbooks_lookups.rst
View file @
d0f8df4b
...
...
@@ -92,6 +92,54 @@ Starting in version 1.4, password accepts a "chars" parameter to allow defining
To enter comma use two commas ',,' somewhere - preferably at the end. Quotes and double quotes are not supported.
.. _csvfile_lookup:
The CSV File Lookup
```````````````````
.. versionadded:: 1.5
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 first column, unless a different column is specified.
The example below shows the contents of a CSV file named elements.csv with information about the
periodic table of elements::
Symbol,Atomic Number,Atomic Mass
H,1,1.008
He,2,4.0026
Li,3,6.94
Be,4,9.012
B,5,10.81
We can use the ``csvfile`` plugin to look up the atomic number or atomic of Lithium by its symbol::
- debug: msg="The atomic number of Lithium is {{ lookup('csvfile', 'Li file=elements.csv delimiter=,') }}"
- debug: msg="The atomic mass of Lithium is {{ lookup('csvfile', 'Li file=elements.csv delimiter=, col=2') }}"
The ``csvfile`` lookup supports several arguments. The format for passing
arguments is::
lookup('csvfile', 'key arg1=val1 arg2=val2 ...')
The first value in the argument is the ``key``, which must be an entry that
appears exactly once in column 0 (the first column, 0-indexed) of the table. All other arguments are optional.
========== ============ =========================================================================================
Field Default Description
---------- ------------ -----------------------------------------------------------------------------------------
file ansible.csv Name of the file to load
delimiter TAB Delimiter used by CSV file. As a special case, tab can be specified as either TAB or \t.
col 1 The column to output, indexed by 0
default empty string return value if the key is not in the csv file
========== ============ =========================================================================================
.. note:: The default delimiter is TAB, *not* comma.
.. _more_lookups:
More Lookups
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment