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

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

     - name: update log
        copy:
          content: "{{ log | to_nice_json}}"
          dest: "{{ log_file }}"
        vars:
          log: "{{ (lookup('file', log_file) | from_json) + ([{'job': (build_id if build_id != '' else 'dev'), 'keystore': ks, 'timestamp': ansible_date_time.iso8601}]) }}"
          log_file: log/log.json
          build_id: "{{ lookup('ENV', 'BUILD_ID') }}"
        tags: log
    

提交回复
热议问题