Append data to json file using ansible modules

已查看 652 次
跳至第一个未读帖子

syam rhel

未读,
2020年4月10日 15:01:582020/4/10
收件人 Ansible Project
Hi All,

Is it possible to update the data of json file using ansible modules.

I tried on windows machine using win_lineinfile module but the required file is not updating.

The line is updating at the end of the file.

Can any one suggest the solution for editing fields in json file.

Thank you,

vinoth kumar

未读,
2020年4月10日 16:16:412020/4/10
收件人 ansible...@googlegroups.com
You have a parameter insert before or insert after where you can regex and update your code. Let us know if it works. Or put your code and error to get it to work 

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/61a135e8-2c2a-4751-b21f-884c25debda3%40googlegroups.com.

Dick Visser

未读,
2020年4月10日 18:12:002020/4/10
收件人 ansible...@googlegroups.com
It depends on your data. 
Please post your json and tell what you want to manipulate exactly. 
Lineinfile sounds fragile. You might have better results with from_json, combine, and to_json.


--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/61a135e8-2c2a-4751-b21f-884c25debda3%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Shyam U

未读,
2020年4月11日 03:15:592020/4/11
收件人 ansible...@googlegroups.com
Hi Vinod and dick,

Thank you, please look at the json file on the remote server. I'm trying to replace the nas path using win_lineinfile, but the path that I'm providing is updating at the end of the file.
 
Hi dick, please update how to do with from_json and to_json.

Json file:

[
    { 
         "Service_id" : "node1"
         "Source_path" : "\\\\192.168.1.1\\data\\nonprod"
         "Source_type" : "NAS"
         "Deztination_type": "Nas"
      }
]

Playbook:

Win_lineinfile:
   Path: D:\\dest\\config.json
   regexp : '^source_path'
   insertafter: '^service_id'
   line: '\\\\192.168.1.2\\data\\nonprod'
   state: present

Thankyou,
Shyam



回复全部
回复作者
转发
0 个新帖子