Hi, I hope you are well
Im blocked to register variable to use in other task:
Here is the tree structure:
└── ansible-role
├── add_user.yml
├── collections
│ └── requirements.yml
├── Export-Test.csv
├── roles
├── gargentieri.search
│ └── tasks
│ └── main.yml
├── gargentieri.csv
└── tasks
└── main.yml
I have a CSV file in list with user information for info retrieval and I
would like to use it in another role.
Here is the add_user.yml playbook that is running:
---
- hosts: localhost
gather_facts: no
roles:
- gargentieri.csv
- hosts: 192.168.100.2
gather_facts: no
roles:
- gargentieri.search
Here is the role gargentieri.csv:
gargentieri.csv > tasks > main.yml
---
- name: Read users from CSV file and return a list
community.general.read_csv:
path: Export-Test.csv
delimiter: ';'
register: "userscsv"
delegate_to: localhost
Here is the output of gargentieri.csv:
{
"changed": false,
"dict": {},
"failed": false,
"list": [
{
"Actif": "Oui",
"Code postal": "75000",
"Département": "Ile-De-France",
"Entité": "COMPANY",
"Fixe": "400000000",
"Mail": "[email protected]",
"Manager": "[email protected]",
"Nom": "VALETTE",
"Nom complet": "Michel VALETTE",
"Nom de rue": "Avenue du routier de paris",
"Numéro de rue": "56",
"Pays": "France",
"Portable": "0600000000",
"Poste": "Technicien",
"Poste de manager": "Non",
"Prénom": "Michel",
"Service": "Technique",
"Site": "Paris",
"Ville": "Paris"
}
]
}
This is the gargentieri.search role:
gargentieri.search > tasks > main.yml
---
- name: Retrieve Nom
ansible.builtin.debug:
msg: "{{ userscsv.list[].Nom }}"
But it does not find the register variable "userscsv" in the
gargentieri.search role.
"The task includes an option with an undefined variable. The error was:
'userscsv' is undefined"
While he should get out the "Name", so VALETTE
Do you have an idea please?
Thanks a lot
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/6e08f7de-78b3-48d7-9f99-2d280c193cf6n%40googlegroups.com.