Hi,
I'm looking for some help.

I'm trying to edit with "lineinfile" module a JSON config file:

- name: Task
   lineinfile:
     dest=/etc/pkg/settings.json
     state=present
     regexp='{{ item.key }}'
     line='"{{ item.key }}": {{ item.value }}'
   with_items:
     - { key: 'setting1', value: 'true' }
     - { key: 'setting2', value: '"value2"' }


But, ansible return an error:

Note: The error may actually appear before this position: line x, column y

    regexp='{{ item.key }}'
    line='"{{ item.key }}": {{ item.value }},'
                          ^
This one looks easy to fix.  YAML thought it was looking for the start of a 
hash/dictionary and was confused to see a second "{".  Most likely this was
meant to be an ansible template evaluation instead, so we have to give the 
parser a small hint that we wanted a string instead. The solution here is 
to 
just quote the entire value.

For instance, if the original line was:

    app_path: {{ base_path }}/foo

It should be written as:

    app_path: "{{ base_path }}/foo"

Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

 
I get an hotfix, using this template of key/value format:

- {key: '"setting1":', value: true}
- {key: '"setting2":', value: '"value2"'}

 
Is there another way to do this?

Regards,
Guillaume

-- 
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 post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to