0

I been having problems getting this to work, can anyone provide any insights?

    - name Configuring rsyslog.conf playbook
      hosts: "{{host}}"
      tasks:
      - name: Configuring rsyslog.conf
        lineinfile:
          path: /etc/rsyslog.conf
          regexp: "{{item.regexp}}"
          line: "{{item.line}}"
          state: present
        loop:
        - { regexp='^action\\(type=', line='action(type"omfwd"' }
        - { 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\"' }

My main issue is the 4th loop. I escaped the double quotes to get rid of the "missing comma error" but now I get the "colon error"

EDIT: So my end result I'd like is pretty much this with that 4th loop:

find:

$template defaultTemplate

replace with:

$template defaultTemplate,"<%PRI%>%TIMESTAMP% %HOSTNAME% %syslogtag% %msg% ID:123456789\n"

I'm unable to cut and paste anything from my computer as it's on a different network. The big issue I'm seeing is knowing what needs to be escaped. I thought it was kinda weird that I had to escape the "(" in the first loop. I been trying all kinds of escapes and none seems to work. It would be so much easier if everything placed in single quotes would be what was literally written in, but it doesn't seem to work that way.

Hope this makes it a bit more clear.

EDIT: one thing I'd like to add, is doing these tasks individually works just fine. It's just when I put it in a loop that it doesn't want to work.

Gene
  • 15
  • 4

1 Answers1

2

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.

Mircea Vutcovici
  • 17,619
  • 4
  • 56
  • 83