I want to provision a JSON file with Ansible. The content of this file is a variable in my Ansible's playbook.
And very important for my usecase: I need the indentation & line breaks to be exactly the same as in my variable.
The variable looks like this :
my_ansible_var: 
  {
    "foobar": {
      "foo": "bar"
    },
    "barfoo": {
      "bar": "foo"
    }
  }
And it's use like this in my playbook :
- name: drop the gitlab-secrets.json file
  copy: 
    content: "{{ my_ansible_var }}"
    dest: "/some/where/file.json"
Problem: when this tasks is played, my file is provisionned but as a "one-line" file:
{ "foobar": { "foo": "bar" }, "barfoo": { "bar": "foo" } }
I tried several other ways:
- Retrieve the base64value of my JSON content, and usecontent: "{{ my_ansible_var | b64decode }}": same problem at the end
- I tried playing with YAML block indicator : none of the block indicators helped me with that problem
- I tried adding some filters like to_json,to_nice_json(indent=2): no more luck here
Question:
How in Ansible can I provison a JSON file while keeping the exact indentation I want ?
 
     
    