Ansible: escaping special characters in a regexp loop
First, the json/yaml syntax for the list of dictionaries in the loop should be one of the following (note first item vs the rest of them):
- name: Configuring rsyslog.conf playbook
hosts: localhost
gather_facts: no
tasks:
- debug: var=item
loop:
- regexp: '^action\(type="
line: "action(type"omfwd"'
- { regexp: '^Target=", line: "Target="192.168.1.20" Port="514" Protocol="tcp")' }
- { regexp: '^Target=", line: "Target="192.168.1.20" Port="514" Protocol="tcp")' }
- { regexp: '^$PreserveFQDN', line: '$PreserveFQDN on' }
- { regexp: '^$template defaultTemplate', line: '$template defaultTemplate,\"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag% %msg% ID:123456789\n\"' }
- { regexp: '^$template writeLogs', line: '$template writeLogs,\"/var/log/ID-123456789-%$year%%$month%%$day%.log\"' }
Next, you will need to fix the regexp/line in file too. They are too borked for us to fix them. You need to provide a minimal example of original and modified file.
Read more here: Source link