diff --git a/lib/ansible/executor/play_iterator.py b/lib/ansible/executor/play_iterator.py index 2ca3815e41..8deeac8b4d 100644 --- a/lib/ansible/executor/play_iterator.py +++ b/lib/ansible/executor/play_iterator.py @@ -19,6 +19,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +from ansible import constants as C + from ansible.errors import * from ansible.playbook.block import Block from ansible.playbook.task import Task @@ -130,7 +132,17 @@ class PlayIterator: elif s.run_state == self.ITERATING_SETUP: s.run_state = self.ITERATING_TASKS s.pending_setup = True - if self._play.gather_facts == 'smart' and not host._gathered_facts or boolean(self._play.gather_facts): + + # Gather facts if the default is 'smart' and we have not yet + # done it for this host; or if 'explicit' and the play sets + # gather_facts to True; or if 'implicit' and the play does + # NOT explicitly set gather_facts to False. + + gathering = C.DEFAULT_GATHERING + if ((gathering == 'smart' and not host._gathered_facts) or + (gathering == 'explicit' and boolean(self._play.gather_facts)) or + (gathering == 'implicit' and + (self._play.gather_facts is None or boolean(self._play.gather_facts)))): if not peek: # mark the host as having gathered facts host.set_gathered_facts(True) diff --git a/lib/ansible/playbook/play.py b/lib/ansible/playbook/play.py index 2d31adec64..ecaeac2362 100644 --- a/lib/ansible/playbook/play.py +++ b/lib/ansible/playbook/play.py @@ -58,7 +58,7 @@ class Play(Base, Taggable, Become): _accelerate_port = FieldAttribute(isa='int', default=5099) # should be alias of port # Connection - _gather_facts = FieldAttribute(isa='string', default='smart') + _gather_facts = FieldAttribute(isa='bool', default=None) _hosts = FieldAttribute(isa='list', default=[], required=True, listof=string_types) _name = FieldAttribute(isa='string', default='')