I am using csv python module for importing a csv file
The csv is importing but unable to fetch the values properly.
My main aim is the prompt that takes as server name needs to check from the csv list whether it exists or not...
I have to add 'when' condition also, but unable to separate HOST_NAME from actual hostname(s)...
I need help for 'when' condition and 'looping' of csv contents..
-----------------------------------------------------------------------------------------------------------
File: DBA_Total_server_list_modified.csv
HOST_NAME
zch89vsoedb106
TX11FPSDB01V
TX11FPSDB02V
tx11fpsdb99v
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
Playbook
---
- name: "Play"
hosts: localhost
vars_prompt:
- name: server_name
prompt: "Enter a Server Name:"
private: no
tasks:
- name: Define values from csv
csv_facts:
src: "./DBA_Total_server_list_modified.csv"
- name: Display imported csv
debug:
var: hostvars[inventory_hostname].csv
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
Output
TASK [Display imported csv] ***************************************************************
ok: [localhost] => {
"hostvars[inventory_hostname].csv": [
{
"HOST_NAME": "zch89vsoedb106"
},
{
"HOST_NAME": "TX11FPSDB01V"
},
{
"HOST_NAME": "TX11FPSDB02V"
},
{
"HOST_NAME": "tx11fpsdb99v"
}
]
}