mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
80a7164057
commit
6307267cf3
2 changed files with 23 additions and 3 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue