From 84a40b71c26f396d9556f317445e75aa8794ee27 Mon Sep 17 00:00:00 2001 From: Colin McCarthy Date: Mon, 8 Oct 2018 11:48:46 -0400 Subject: [PATCH] Added (Define Values From CSV File) to example section (#46620) Adding a new example demonstrating setting facts from a CSV file, from a real-world network use case. --- lib/ansible/plugins/lookup/csvfile.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/ansible/plugins/lookup/csvfile.py b/lib/ansible/plugins/lookup/csvfile.py index 0a4298b396..405e6d68a4 100644 --- a/lib/ansible/plugins/lookup/csvfile.py +++ b/lib/ansible/plugins/lookup/csvfile.py @@ -39,6 +39,17 @@ EXAMPLES = """ - 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') }}" + +- name: Define Values From CSV File + set_fact: + loop_ip: "{{ lookup('csvfile', bgp_neighbor_ip +' file=bgp_neighbors.csv delimiter=, col=1') }}" + int_ip: "{{ lookup('csvfile', bgp_neighbor_ip +' file=bgp_neighbors.csv delimiter=, col=2') }}" + int_mask: "{{ lookup('csvfile', bgp_neighbor_ip +' file=bgp_neighbors.csv delimiter=, col=3') }}" + int_name: "{{ lookup('csvfile', bgp_neighbor_ip +' file=bgp_neighbors.csv delimiter=, col=4') }}" + local_as: "{{ lookup('csvfile', bgp_neighbor_ip +' file=bgp_neighbors.csv delimiter=, col=5') }}" + neighbor_as: "{{ lookup('csvfile', bgp_neighbor_ip +' file=bgp_neighbors.csv delimiter=, col=6') }}" + neigh_int_ip: "{{ lookup('csvfile', bgp_neighbor_ip +' file=bgp_neighbors.csv delimiter=, col=7') }}" + delegate_to: localhost """ RETURN = """