Only use hosts kwarg in `local.include` if a valid value.
@@ -9,26 +9,28 @@ from subprocess import PIPE, Popen, STDOUT
import six
-from . import pseudo_inventory, pseudo_state
+from . import logger, pseudo_inventory, pseudo_state
from .api.exceptions import PyinfraError
from .api.util import ensure_host_list, exec_file, read_buffer
-def include(filename, hosts=None):
+def include(filename, hosts=False):
'''
Executes a local python file within the ``pyinfra.pseudo_state.deploy_dir``
directory.
'''
- if not pseudo_state.active:
- return
-
filename = path.join(pseudo_state.deploy_dir, filename)
- hosts = ensure_host_list(hosts, pseudo_inventory)
+ logger.debug('Including local file: {0}'.format(filename))
- with pseudo_state.limit(hosts):
try:
+ if hosts is not False:
+ hosts = ensure_host_list(hosts, pseudo_inventory)
+ with pseudo_state.limit(hosts):
+ exec_file(filename)
+
+ else:
exec_file(filename)
except IOError as e:
