Add a new key-value to a json file using Ansible

前端 未结 4 1628
孤独总比滥情好
孤独总比滥情好 2021-02-13 01:47

I\'m using Ansible to automate some configuration steps for my application VM, but having difficult to insert a new key-value to an existing json file on the remote host.

<
4条回答
  •  鱼传尺愫
    2021-02-13 02:36

    ilias-sp's solution is great!

    In my case, it lacked the case when we may have to create a base json file. So I had to add this task in the beginning of the play:

    - name: Ensure json file exists
    copy:
      content: "{}"
      dest: /tmp/var.json
      force: false
    

提交回复
热议问题