The key thing to remember is that the in-target
commands are executed in a chroot
environment. They are not executed in a fully booted system where core processes like systemd are running and available.
Testing
I setup a playbook based on the STIG tasks in the screenshot and ran it from the preseed. I saw the same results as you.
---
- hosts: localhost
gather_facts: no
connection: local
tasks:
- name: check if rsyslog.service is installed
shell: ! systemctl list-unit-files | grep "^rsyslog.service[ \t]\+"
changed_when: False
check_mode: no
register: result
failed_when: result.rc > 1
- name: stigrule_219160_rsyslog_enable
service:
name: rsyslog.service
enabled: "yes"
d-i pkgsel/include string ansible
d-i preseed/late_command string \
wget -P /target/ http://REDACTED/my_playbook.yml ; \
in-target ansible-playbook -i /dev/null -b -v /my_playbook.yml
Bionic packages ansible 2.5.1
and that version of the service module appears to execute systemctl show rsyslog.service
. This does not work in a chroot environment. To demonstrate, if I open a terminal in the installer environment and run in-target systemctl show rsyslog.service
then the log file will show the output
in-target: Running in chroot, ignoring request: show
Potential Fix
I did find a patch in Ansible 2.3 that addresses the problem that systemctl will ignore commands when running in a chroot environment. This was only applied to the systemd
module though and not the service
module. I updated my playbook and this does run successfully.
---
- hosts: localhost
gather_facts: no
connection: local
tasks:
- name: check if rsyslog.service is installed
shell: ! systemctl list-unit-files | grep "^rsyslog.service[ \t]\+"
changed_when: False
check_mode: no
register: result
failed_when: result.rc > 1
- name: stigrule_219160_rsyslog_enable fixed
systemd:
name: rsyslog.service
enabled: "yes"
Therefore, you may be able to progress further by modifying the STIG task(s) from using the service
module to using the systemd
module.