Ensure rsyslog restarts after configuration file changes

Added rsyslog restart handlers to each rsyslog_server_post_install task.
There was an issue when rsyslog_post_install would stop its service,
it would automatically get restarted and the service would not listen
for incoming logs. This now ensures that the rsyslog service will
be restarted after configuration files are changed.
Add rsyslog_pid_name to variable files for distrubition changes for rsyslogd pid

Change-Id: I757387e8f7f7209b1ab928208894ecf4bf510efc
Partial-Bug: 1636017
This commit is contained in:
Jarrad Battaglia 2017-02-01 05:07:35 +00:00
parent 3ca2f1e7b0
commit a09e5ea5a6
5 changed files with 33 additions and 14 deletions

7
handlers/main.yml Normal file
View File

@ -0,0 +1,7 @@
---
- name: restart rsyslog
service:
name: rsyslog
state: restarted

View File

@ -13,14 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Stop rsyslog
service:
name: "rsyslog"
state: "stopped"
failed_when: false
tags:
- rsyslog_server_install
- name: Rsyslog basic setup
template:
src: "{{ item.src }}"
@ -32,6 +24,8 @@
- { src: "os_aggregate_storage.j2", dest: "/etc/logrotate.d/os_aggregate_storage" }
tags:
- rsyslog_server-config
notify:
- restart rsyslog
- name: Rsyslog defaults setup
copy:
@ -41,6 +35,8 @@
group: "root"
tags:
- rsyslog_server-config
notify:
- restart rsyslog
- name: Configure logrotate to compress logs by default
lineinfile:
@ -51,9 +47,3 @@
tags:
- rsyslog_server_install
- name: Start rsyslog
service:
name: "rsyslog"
state: "started"
tags:
- rsyslog_server-config

View File

@ -34,3 +34,23 @@
that:
- "'template(name=\"DDF' in (rsyslog_conf.content | b64decode)"
- "os_aggregate_storage.stat.exists"
- name: Stat rsyslog pid file
stat:
path: /var/run/{{rsyslog_pid_name}}
register: stat_rsyslog_pid
- name: Stat /etc/rsyslog.d/50-default.conf
stat:
path: /etc/rsyslog.d/50-default.conf
register: stat_50_default_conf
- name: Stat /etc/rsyslog.conf
stat:
path: /etc/rsyslog.conf
register: stat_rsyslog_conf
- assert:
that:
- "stat_rsyslog_pid.stat.mtime > stat_rsyslog_conf.stat.mtime"
msg: "/etc/rsyslog.conf was updated without restarting rsyslogd. Configuration changes have not been applied."
- assert:
that:
- "stat_rsyslog_pid.stat.mtime > stat_50_default_conf.stat.mtime"
msg: "/etc/rsyslog.d/50-default.conf was updated without restarting rsyslogd. Configuration changes have not been applied."

View File

@ -16,3 +16,4 @@
rsyslog_server_distro_packages:
- rsyslog
- logrotate
rsyslog_pid_name: rsyslogd.pid

View File

@ -16,3 +16,4 @@
rsyslog_server_distro_packages:
- rsyslog
- logrotate
rsyslog_pid_name: syslogd.pid