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

前端 未结 4 1627
孤独总比滥情好
孤独总比滥情好 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:33

    For people who are OK with custom ansible modules: https://github.com/ParticleDecay/ansible-jsonpatch works great!

    With this you can simply do:

    - name: append key/values
      json_patch:
        src: /tmp/var.json
        operations:
          - op: add
            path: "/hello"
            value: "world"
        pretty: yes
        create: yes
    

提交回复
热议问题