0

I'm trying to update an appsettings.json file on each one of my nodes. When I run my playbook, I'm getting a changed state for all my nodes but when I check the node I don't see any changes to the line. I'm also trying to update the string with the hostname but that doesn't seem to be working very well.

Here is an example of what I'm trying to do:

- 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}}\\",'

Here is a snippet of the appsettings:

  },
  "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/"
TravelingLex
  • 399
  • 1
  • 3
  • 16

1 Answers1

0

The issue was because of the documentation: https://docs.ansible.com/ansible/latest/modules/win_lineinfile_module.html#examples

I was able to get it working by changing to:

- 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}}\\",'
TravelingLex
  • 399
  • 1
  • 3
  • 16