I have the following code and realised that under the debug section.
-
name: CIS Requirements check
hosts: target1
tasks:
-
name: Check for CIS PermitRootLogin
lineinfile:
path: /etc/ssh/sshd_config
regexp: '^\s*PermitRootLogin\s+no\s*$'
state: absent
check_mode: yes
register: permitrootlogin_check
-
debug:
msg: "{% if permitrootlogin_check.changed %}[PASSED] SSH root login disabled{% else %}[FAILED] SSH root login not disabled{% endif %}"
register: permitrootlogin_results
permitrootlogin_check.changed would help to achieve the same objective as permitrootlogin_check.found.
However I also noticed that while .change is dependent on the state present/absent, .found is not dependent on the state and .found also does not seem to work with the state: present.
Why is this so?