--- - name: Check if /etc/rsyslogd.conf exists ansible.builtin.stat: path: /etc/rsyslog.conf register: rsyslogd_conf - name: Disable kernel logging ansible.builtin.lineinfile: path: /etc/rsyslog.conf regexp: '^[\s#]*(.*imklog.*)$' line: '#\1' backrefs: true backup: yes when: rsyslogd_conf.stat.exists notify: Restart Rsyslog