使用 win_lineinfile 未在文件中更新行

Line not updating in a file using win_lineinfile

我正在尝试更新每个节点上的 appsettings.json 文件。当我 运行 我的剧本时,我的所有节点的状态都发生了变化,但是当我检查节点时,我没有看到该行有任何变化。我也在尝试用主机名更新字符串,但似乎效果不佳。

这是我正在尝试做的一个例子:

- name: Replace line in appsettings.json
  win_lineinfile:
    path: C:\BatchJobs\appsettings.json
    regex: '"SrcDir:"\s*:\s*"[^"]*",'
    line: '"SrcDir:" "\\<ip-address>\D$\ETLs\{{ansible_hostname}}\",'

这是应用程序设置的一个片段:

  },
  "DirectorySettings": {
    "FileSettingsConfigFile": "\\10.34.0.202\D$\Config\<config>",
    "SrcDir": "\\<ip-Address>\D$\ETLs\ETL01\",
    "DestinationDir": "D:\DestinationDir\",
    "ShipDir": "D:\ShipDir\",
    "FailedDir": "\\10.34.0.202\D$\FailedDir\",
    "DBQueriesBaseFolder": "./config/JobQueries/",
    "FileStatJobConfig": "./config/FileStat/"

问题是由于文档:https://docs.ansible.com/ansible/latest/modules/win_lineinfile_module.html#examples

我可以通过更改为:

来让它工作
- name: Replace line in appsettings.json
  win_lineinfile:
    path: C:\BatchJobs\appsettings.json
    regexp: '"SrcDir:"\s*:\s*"[^"]*",'
    line: '"SrcDir:" "\\<ip-address>\D$\ETLs\{{ansible_hostname}}\",'