diff --git a/lib/ansible/playbook.py b/lib/ansible/playbook.py index ba5115d02d9..695895624b5 100755 --- a/lib/ansible/playbook.py +++ b/lib/ansible/playbook.py @@ -313,7 +313,7 @@ class PlayBook(object): setup_cache=SETUP_CACHE, basedir=self.basedir, conditional=only_if, callbacks=self.runner_callbacks, extra_vars=self.extra_vars, debug=self.debug, sudo=sudo, - transport=transport, sudo_pass=self.sudo_pass + transport=transport, sudo_pass=self.sudo_pass, is_playbook=True ) if async_seconds == 0: @@ -475,7 +475,7 @@ class PlayBook(object): remote_pass=self.remote_pass, remote_port=self.remote_port, setup_cache=SETUP_CACHE, callbacks=self.runner_callbacks, sudo=sudo, debug=self.debug, - transport=transport, sudo_pass=self.sudo_pass + transport=transport, sudo_pass=self.sudo_pass, is_playbook=True ).run() self.stats.compute(setup_results, setup=True) diff --git a/lib/ansible/runner.py b/lib/ansible/runner.py index 418a069ba8c..a715b531251 100755 --- a/lib/ansible/runner.py +++ b/lib/ansible/runner.py @@ -76,7 +76,7 @@ class Runner(object): sudo_pass=C.DEFAULT_SUDO_PASS, remote_port=C.DEFAULT_REMOTE_PORT, background=0, basedir=None, setup_cache=None, transport=C.DEFAULT_TRANSPORT, conditional='True', groups={}, callbacks=None, verbose=False, - debug=False, sudo=False, extra_vars=None, module_vars=None): + debug=False, sudo=False, extra_vars=None, module_vars=None, is_playbook=False): if setup_cache is None: setup_cache = {} @@ -117,6 +117,7 @@ class Runner(object): self.basedir = basedir self.sudo = sudo self.sudo_pass = sudo_pass + self.is_playbook = is_playbook euid = pwd.getpwuid(os.geteuid())[0] if self.transport == 'local' and self.remote_user != euid: @@ -401,6 +402,23 @@ class Runner(object): # ***************************************************** + def _save_setup_result_to_disk(self, conn, result): + ''' cache results of calling setup ''' + + dest = os.path.expanduser("~/.ansible/setup_data") + if self.remote_user == 'root': + dest = "/var/lib/ansible/setup_data" + if not os.path.exists(dest): + os.makedirs(dest) + + fh = open(os.path.join(dest, conn.host), "w") + fh.write(result) + fh.close() + + return result + + # ***************************************************** + def _add_result_to_setup_cache(self, conn, result): ''' allows discovered variables to be used in templates and action statements ''' @@ -434,6 +452,8 @@ class Runner(object): if module_name == 'setup': self._add_result_to_setup_cache(conn, result) + if self.is_playbook: + self._save_setup_result_to_disk(conn, result) return self._return_from_module(conn, host, result, err, executed)