Issue #2187287 by ivanbreet: Backport D7 patch from el7cosmos with some minor alterations.