diff --git a/salt/master.py b/salt/master.py
index <HASH>..<HASH> 100644
--- a/salt/master.py
+++ b/salt/master.py
@@ -667,8 +667,8 @@ class AESFuncs(object):
         mopts = dict(self.opts)
         file_roots = dict(mopts['file_roots'])
         envs = self._file_envs()
-        for env in file_roots:
-            if not env in envs:
+        for env in envs:
+            if not env in file_roots:
                 file_roots[env] = []
         mopts['file_roots'] = file_roots
         return mopts
Fix bug in environment gathering on the master