As part of the support for access to external nodes information, save fact data into /var/lib/ansible/setup_data
OR a per-user directory when running from playbooks. Technically this info is also available via the SETUP_CACHE but that is a bit more complex of a construct and it would be better to not cross the streams.
This commit is contained in:
parent
31d4ee32d1
commit
3454fa9950
2 changed files with 23 additions and 3 deletions
|
@ -313,7 +313,7 @@ class PlayBook(object):
|
||||||
setup_cache=SETUP_CACHE, basedir=self.basedir,
|
setup_cache=SETUP_CACHE, basedir=self.basedir,
|
||||||
conditional=only_if, callbacks=self.runner_callbacks,
|
conditional=only_if, callbacks=self.runner_callbacks,
|
||||||
extra_vars=self.extra_vars, debug=self.debug, sudo=sudo,
|
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:
|
if async_seconds == 0:
|
||||||
|
@ -475,7 +475,7 @@ class PlayBook(object):
|
||||||
remote_pass=self.remote_pass, remote_port=self.remote_port,
|
remote_pass=self.remote_pass, remote_port=self.remote_port,
|
||||||
setup_cache=SETUP_CACHE,
|
setup_cache=SETUP_CACHE,
|
||||||
callbacks=self.runner_callbacks, sudo=sudo, debug=self.debug,
|
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()
|
).run()
|
||||||
self.stats.compute(setup_results, setup=True)
|
self.stats.compute(setup_results, setup=True)
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ class Runner(object):
|
||||||
sudo_pass=C.DEFAULT_SUDO_PASS, remote_port=C.DEFAULT_REMOTE_PORT, background=0,
|
sudo_pass=C.DEFAULT_SUDO_PASS, remote_port=C.DEFAULT_REMOTE_PORT, background=0,
|
||||||
basedir=None, setup_cache=None, transport=C.DEFAULT_TRANSPORT,
|
basedir=None, setup_cache=None, transport=C.DEFAULT_TRANSPORT,
|
||||||
conditional='True', groups={}, callbacks=None, verbose=False,
|
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:
|
if setup_cache is None:
|
||||||
setup_cache = {}
|
setup_cache = {}
|
||||||
|
@ -117,6 +117,7 @@ class Runner(object):
|
||||||
self.basedir = basedir
|
self.basedir = basedir
|
||||||
self.sudo = sudo
|
self.sudo = sudo
|
||||||
self.sudo_pass = sudo_pass
|
self.sudo_pass = sudo_pass
|
||||||
|
self.is_playbook = is_playbook
|
||||||
|
|
||||||
euid = pwd.getpwuid(os.geteuid())[0]
|
euid = pwd.getpwuid(os.geteuid())[0]
|
||||||
if self.transport == 'local' and self.remote_user != euid:
|
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):
|
def _add_result_to_setup_cache(self, conn, result):
|
||||||
''' allows discovered variables to be used in templates and action statements '''
|
''' allows discovered variables to be used in templates and action statements '''
|
||||||
|
|
||||||
|
@ -434,6 +452,8 @@ class Runner(object):
|
||||||
|
|
||||||
if module_name == 'setup':
|
if module_name == 'setup':
|
||||||
self._add_result_to_setup_cache(conn, result)
|
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)
|
return self._return_from_module(conn, host, result, err, executed)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue