On Tue, 18 Feb 2020 at 13:39, Jerome Meyer <[email protected]> wrote:
> Hi Team, > > I'm encountered some issue with set_facts from variable with json and for > this reason I'm tried to understand this. To reproduce this case I'm using > the example from here : playbooks filters > <https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#filters-for-formatting-data> > > tasks > - shell: cat /some/path/to/file.json > register: result > > - set_fact: > myvar: "{{ result.stdout | from_json }}" > > This here below looks like your example.json file actually contains yaml which in turn contains json? > I've created one example.fson file : > # cat files/example.json > json_example: | > { > "example_simple": { > "name": "simple", > "foo": "value", > "item": "this" > }, > } > > > Here's the task file : > # cat tasks/main.yml > --- > - name: Read JSON file > shell: cat ../files/example.json > register: json > > - name: Get simple value. > set_fact: > simple_value: "{{ (json.stdout | from_json).example_simple.name }}" > > > - name: Simple debug. > debug: > msg: "{{ simple_value }}" > > > And here the result: > fatal: [localhost]: FAILED! => {"msg": "the field 'args' has an invalid > value ({u'simple_value': u'{{ (json.stdout | from_json) }}'}), and could > not be converted to an dict.The error was: No JSON object could be > decoded\n\nThe error appears to be in > '/etc/ansible/roles/testrole/tasks/main.yml': line 7, column 3, but may\nbe > elsewhere in the file depending on the exact syntax problem.\n\nThe > offending line appears to be:\n\n\n- name: Get simple value.\n ^ here\n"} > > It tells me that the input cannot be converted to dict, But why and what > is the problem? Could someone explain me this problem? > I cannot understand what is wrong. > > Best regards, J > > > > > > > -- > 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/76189198-429c-4025-98f8-92e7f69ff417%40googlegroups.com > <https://groups.google.com/d/msgid/ansible-project/76189198-429c-4025-98f8-92e7f69ff417%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- Sent from a mobile device - please excuse the brevity, spelling and punctuation. -- 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/CAL8fbwMgyNjhT0Kmgy80DBj4ykeUEMMar6_7rUc4i8nDrcLvuQ%40mail.gmail.com.
