I continually find that certain things "just don't work" when run as preseed/late_command in an Ubuntu Bionic preseed file. (The same applies to autoinstall for Ubuntu Focal.) In this particular case, I'm attempting to run an Ansible Role (specifically, the Canonical Ubuntu 18.04 LTS for Ansible STIG) against the target as a late_command:
d-i preseed/late_command string \
in-target /usr/bin/curl -fsSL -o /opt/stig.zip {{ di_preseed.stig_role_url }}; \
in-target /usr/bin/unzip -qq /opt/stig.zip -d /opt; \
in-target /usr/bin/unzip -qq /opt/ubuntu1804STIG-ansible.zip -d /opt; \
in-target /bin/sh -c -- 'cd /opt && ANSIBLE_LOG_PATH=/var/log/ansible.log /bin/sh enforce.sh'
Here enforce.sh is just a wrapper around ansible-playbook.
This install from ISO on Virtualbox fails with:
Failed to run preseeded command ... <command> finished with exit code 2
I am still able to log in to the box as ubuntu and become root. I see that Ansible was successfully installed (it is originally specified in pkgsel/include).
I then open up /var/log/installer/syslog on the target and find that ansible-playbook failed when it could not find rsyslog.service:
This is confusing as rsyslog.service is most certainly enabled and active after the install, which I can confirm with systemctl (status|is-active) rsyslog.
So what I'm seeking to understand here is:
- Why is Ansible unable to find
rsyslog.serviceduring install even though it appears to be enabled? - What factors are different about the installation that result in things seeming to commonly break or not be available?
- Would I be better of running this as an onboot script under init.rc, then last line it removes itself after done?
Related: Certain commands (e.g. modprobe or usermod) fail as late-commands in Ubuntu autoinstall

ctrl+zwill get you into a bash shell as root in the installer environment with /cdrom and /target sitting on the filesystem (the former being the mounted iso). That opened up a whole lot of easier debugging including discovering, as you mention here, that most of systemctl isn't available in a chroot environment. So that's not an ansible problem, per se, and the fact that curtin in-target is a chroot /target under the hood seems to be the underlying cause of most behavioral issues I've encountered. – Brad Solomon Aug 04 '21 at 17:33Alt-F2. See https://askubuntu.com/a/1257186/376778 . You can even SSH into the installer environment if you set (or capture) theinstalleruser password (YMMV depending on subiquity version): https://askubuntu.com/a/1322129/376778 – Andrew Lowther Aug 04 '21 at 18:48