This task collection doesn\'t work as I hoped it would:
- name: Find out whether syslog-ng is installed (yum)
tags: syslog_forwarding
command: yum -q list in
There are only workarounds. Skipped tasks will always overwrite registered variable.
One possible way:
- name: Find out whether syslog-ng is installed (yum)
tags: syslog_forwarding
command: yum -q list installed syslog-ng
register: syslog_ng_check
failed_when: False
changed_when: False
when: ansible_pkg_mgr == 'yum'
- set_fact:
syslog_ng_flag: True
when: syslog_ng_check.rc == 0
- name: Find out whether syslog-ng is installed (apt)
tags: syslog_forwarding
command: dpkg -s syslog-ng
register: syslog_ng_check
failed_when: False
changed_when: False
when: ansible_pkg_mgr == 'apt'
- set_fact:
syslog_ng_flag: True
when: syslog_ng_check.rc == 0
- name: Configure syslog-ng to forward all logs to syslog servers (apt)
tags: syslog_forwarding
template:
src: syslog_ng_forward_all.conf.j2
dest: /etc/syslog-ng/conf.d/syslog_forward.conf
notify: restart syslog_ng
when: syslog_ng_flag | default(false)