Problem with Ansible Form when reading JSON file in the form #271
-
Hello everyone, I am trying to load a dropdown list in an Ansible form using data from a JSON file, but it keeps loading and doesn’t work. I would appreciate any help. I have this JSON file: [
{ "id": 1, "name": "Ana", "department": "Sales" },
{ "id": 2, "name": "Luis", "department": "Marketing" },
{ "id": 3, "name": "María", "department": "Sales" }
] And this form: name: Read JSON
type: ansible
playbook: leer.yaml
roles:
- admin
categories:
- Fedora
tileClass: has-background-info-light
icon: spider
fields:
- type: enum
name: empleados
label: Employee List
expression: fn.fnReadJsonFile('empleados.json','.[].name')
runLocal: true
source: Fedora.yaml The Ansible playbook looks like this: ---
- name: Process form data
hosts: localhost
gather_facts: no
tasks:
- name: Show selected employee
debug:
msg: "Selected employee: {{ empleados }}" The problem is that the form keeps loading with this error in the logs:
I’ve already checked that the JSON file path is correct, but I don’t understand what’s causing this error. Additionally, I tried testing the Pet Store API using Has anyone managed to make something like this work? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
remove runLocal. |
Beta Was this translation helpful? Give feedback.
-
api calls and reading files are backend actions. not frontend |
Beta Was this translation helpful? Give feedback.
ok... here we go
In my docker compose, I map a local folder to the persistent directory of the container.
This way, playbooks, forms, database => all consistent in case the container is recreated.
In my local data folder (mounted to the container):
When I go into my container, I find the exact same files:
Of which my json file
Now let's use the file, consider this field in the form
Let's filter it with jq (although, you can just use the property
columns