Refactor play._update_vars_files_for_host to make common functions and easier debugging

Fixes #4883
Add unit tests for vars_files