From 639ec023f1a1a7e880a4675ddc6016fdb8ff68ab Mon Sep 17 00:00:00 2001 From: David Murphy < dmurphy@saltstack.com> Date: Wed, 13 Sep 2023 10:38:33 -0600 Subject: [PATCH] Ensure sync from _grains occurs before attempting pillar compilation in case custom grain used in pillar file --- changelog/65027.fixed.md | 1 + salt/minion.py | 5 +++++ salt/state.py | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelog/65027.fixed.md diff --git a/changelog/65027.fixed.md b/changelog/65027.fixed.md new file mode 100644 index 00000000000..43289c688b2 --- /dev/null +++ b/changelog/65027.fixed.md @@ -0,0 +1 @@ +Ensure sync from _grains occurs before attempting pillar compilation in case custom grain used in pillar file diff --git a/salt/minion.py b/salt/minion.py index f4d9b6be47a..541cfef3520 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -73,6 +73,7 @@ from salt.template import SLS_ENCODING from salt.utils.ctx import RequestContext from salt.utils.debug import enable_sigusr1_handler from salt.utils.event import tagify +from salt.utils.extmods import sync as _sync from salt.utils.network import parse_host_port from salt.utils.odict import OrderedDict from salt.utils.process import ProcessManager, SignalHandlingProcess, default_signals @@ -920,6 +921,8 @@ class SMinion(MinionBase): # Late setup of the opts grains, so we can log from the grains module import salt.loader + # need sync of custom grains as may be used in pillar compilation + _sync(opts, "grains") opts["grains"] = salt.loader.grains(opts) super().__init__(opts) @@ -3936,6 +3939,8 @@ class SProxyMinion(SMinion): salt '*' sys.reload_modules """ + # need sync of custom grains as may be used in pillar compilation + _sync(self.opts, "grains") self.opts["grains"] = salt.loader.grains(self.opts) self.opts["pillar"] = salt.pillar.get_pillar( self.opts, diff --git a/salt/state.py b/salt/state.py index d5956981eed..449f84e5d19 100644 --- a/salt/state.py +++ b/salt/state.py @@ -4254,7 +4254,7 @@ class BaseHighState: """ if not self.opts["autoload_dynamic_modules"]: return - syncd = self.state.functions["saltutil.sync_all"](list(matches), refresh=False) + syncd = self.state.functions["saltutil.sync_all"](list(matches), refresh=True) if syncd["grains"]: self.opts["grains"] = salt.loader.grains(self.opts) self.state.opts["pillar"] = self.state._gather_pillar()