Greetings everyone! I am beating my head against a wall trying to get this to work, and I know I’m screwing it up but I’m about at the end of my tether trying to get this right. I’m trying to add customFields to IIS site logs, and have tried win_command and win_shell to accomplish this, and I am just not finding the right way to escape it in either module.
Environment: Amazon Linux with Ansible 2.4 - Target Hosts: Windows Server 2016
The win_command I am trying to run is this:
`
- name: Enable X-Forwarded-For Logging
win_command: C:\Windows\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites /+"[name=‘{{ app_url }}’].logFile.customFields.[logFieldName=‘X-Forwarded-For’,sourceName=‘X-Forwarded-For’,sourceType=‘RequestHeader’]" /commit:apphost
`
The result I get for this is:
e[0;31mfatal: [IP_REDACTED]: FAILED! => {e[0m
e[0;31m "changed": true, e[0m
e[0;31m "cmd": "C:\Windows\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites /+\\"[name='APP_NAME_REDACTED'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-Forwarded-For',sourceType='RequestHeader']\\" /commit:apphost", e[0m
e[0;31m "delta": "0:00:00.390647", e[0m
e[0;31m "end": "2018-03-14 01:00:03.620441", e[0m
e[0;31m "msg": "non-zero return code", e[0m
e[0;31m "rc": 1413, e[0m
e[0;31m "start": "2018-03-14 01:00:03.229794", e[0m
e[0;31m "stderr": "", e[0m
e[0;31m "stderr_lines": [], e[0m
e[0;31m "stdout": "ERROR ( message:Unknown attribute \"\"[name='APP_NAME_REDACTED'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-Forwarded-For',sourceType='RequestHeader']\"\". Replace with -? for help. )\r\n", e[0m
e[0;31m "stdout_lines": [e[0m
e[0;31m "ERROR ( message:Unknown attribute \"\"[name='APP_NAME_REDACTED'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-Forwarded-For',sourceType='RequestHeader']\"\". Replace with -? for help. )"e[0m
e[0;31m ]e[0m
I've tried this multiple times, with various sets of single quotes, double quotes, etc. and am bombing every time. Here is the raw command without any escaping I'm trying to run, can anyone help point me towards getting this right please?
appcmd.exe set config -section:system.applicationHost/sites /+"[name='APP_NAME_REDACTED'].logFile.customFields.[logFieldName='X-Forwarded-For',sourceName='X-Forwarded-For',sourceType='RequestHeader']" /commit:apphost
Thanks in advance for any and all help!