Raise an exception to kill the deploy if we can't connect to a host when trying to get a fact from it.
@@ -8,6 +8,7 @@ import click
from .attrs import wrap_attr_data
from .connectors import EXECUTION_CONNECTORS
+from .exceptions import PyinfraError
from .facts import get_fact, is_fact
@@ -21,7 +22,14 @@ class HostFacts(object):
raise AttributeError('No such fact: {0}'.format(key))
# Ensure this host is connected
- self.host.connect(self.inventory.state, for_fact=key)
+ connection = self.host.connect(self.inventory.state, for_fact=key)
+
+ # If we can't connect - fail immediately as we specifically need this
+ # fact for this host and without it we cannot satisfy the deploy.
+ if not connection:
+ raise PyinfraError('Could not connect to {0} for fact {1}!'.format(
+ self.host, key,
+ ))
fact = get_fact(self.inventory.state, self.host, key)
return wrap_attr_data(key, fact)
