I am starting to look into using ansible for maintaining a set of servers. I have ran into a difficulty with lineinfile. I am setting up rsyslog and want to make sure a few lines are in the /etc/rsyslog.conf:
- name: set up rsyslog
lineinfile:
dest: /etc/rsyslog.conf
line: '{{ item }}'
with_items:
- "*.* @@rsysserver.example.com:514"
- "*.info;mail.none;authpriv.none;cron.none;user.none /var/log/messages"
- "user.* -/var/log/user_messages"
This works fine on a new box, but my problem is that some of the servers have been hand-maintained for a while and that means that the amount of whitespace in the lines may differ, so if there should be a line like user.* -/var/log/user_messages ansible will add on the last item in the rule above.
I could make three different rules like
lineinfile:
dest: /etc/rsyslog.conf
line: user.* -/var/log/user_messages
regexp: 'user.\*\s+-/var/log/user_messages'
state: present
should work, but then I need to write three different rules to add the three lines to /etc/syslog.conf.
Is there any way I can set up one rule to maintain the file but use different regexes for each of the lines I want to add?