Fix #5679 again after recent changes in core

My previous fix for #5679 stop working after some recent changes in Ansible and the test case I’ve wrote wasn’t ported to the new test suite. There’s a fix that works on the current version and also a new test.