(Fixes #9008.) With credit to jimi-c for the initial pass in this commit: https://github.com/jimi-c/ansible/commit/b18bd6b98edecda1fcb5a85053593e78b46b9709