Actually use the variable cache

* The merged (host+local) variable cache should not be reset at each
    instruction.
This commit is contained in:
Emmanuel BENOîT 2022-09-04 23:14:01 +02:00
parent 7e5eb8e414
commit d1d997f7ae

View file

@ -214,9 +214,7 @@ class RcInstruction(abc.ABC):
def parse_action(self, record): def parse_action(self, record):
raise NotImplementedError raise NotImplementedError
def run_for(self, host_name, host_vars, script_vars): def run_for(self, host_name, merged_vars, host_vars, script_vars):
merged_vars = host_vars.copy()
merged_vars.update(script_vars)
if self._loop is None: if self._loop is None:
self._display.vvvv("%s : running action %s" % (host_name, self._action)) self._display.vvvv("%s : running action %s" % (host_name, self._action))
return self.run_once(host_name, merged_vars, host_vars, script_vars) return self.run_once(host_name, merged_vars, host_vars, script_vars)
@ -654,7 +652,7 @@ class RciBlock(RcInstruction):
def run_block(self, block, host_name, merged_vars, host_vars, script_vars): def run_block(self, block, host_name, merged_vars, host_vars, script_vars):
for instruction in block: for instruction in block:
if not instruction.run_for(host_name, host_vars, script_vars): if not instruction.run_for(host_name, merged_vars, host_vars, script_vars):
return False return False
return True return True
@ -711,9 +709,10 @@ class InventoryModule(BaseInventoryPlugin):
def exec_for_host(self, host, instructions): def exec_for_host(self, host, instructions):
host_vars = self.inventory.get_host(host).get_vars() host_vars = self.inventory.get_host(host).get_vars()
var_cache = host_vars.copy()
script_vars = {} script_vars = {}
for instruction in instructions: for instruction in instructions:
if not instruction.run_for(host, host_vars, script_vars): if not instruction.run_for(host, var_cache, host_vars, script_vars):
return return
def dump_program(self, instructions): def dump_program(self, instructions):