Issues with an jinja and magic variables script any help would be awesome

I’m going to guess that you probably don’t have facts cached (or the cache has expired) for the hosts where the variable is undefined.