Improved inventory handling when inventory does not yet exist

Fixes #8324
Improves #7667

As discussed with @mpdehaan on ansible-devel.