diff --git a/conf/minion b/conf/minion index 70cbe8934a45..328c11b035c8 100644 --- a/conf/minion +++ b/conf/minion @@ -384,6 +384,12 @@ # protected accordingly. #minion_pillar_cache: False +# When set to True the minion will not request a pillar from the master upon +# startup. Pillar can still be fetched later via a manual operation like +# `saltutil.refresh_pillar` or similar. Enabling this option might break pillar +# related functionality (e.g. pillar targeter). +#skip_init_pillar: False + # Grains cache expiration, in seconds. If the cache file is older than this # number of seconds then the grains cache will be dumped and fully re-populated # with fresh data. Defaults to 5 minutes. Will have no effect if 'grains_cache' diff --git a/salt/cli/call.py b/salt/cli/call.py index be3ded77e64e..e700f48014cd 100644 --- a/salt/cli/call.py +++ b/salt/cli/call.py @@ -46,6 +46,11 @@ def run(self): self.config["extension_modules"] = os.path.join(cache_dir, "extmods") prepend_root_dir(self.config, ["cachedir", "extension_modules"]) + if self.config["fun"].split(".")[0] == "pillar": + if self.options.skip_init_pillar: + self.options.skip_init_pillar = False + self.config["skip_init_pillar"] = False + caller = salt.cli.caller.Caller.factory(self.config) if self.options.doc: diff --git a/salt/config/__init__.py b/salt/config/__init__.py index dba7f316801d..b2ea83099aa8 100644 --- a/salt/config/__init__.py +++ b/salt/config/__init__.py @@ -621,6 +621,11 @@ def _gather_buffer_space(): "pillar_cache_ttl": int, # Pillar cache backend. Defaults to `disk` which stores caches in the master cache "pillar_cache_backend": str, + # When set to True the minion will not request a pillar from the master upon startup. + # Pillar can still be fetched later via a manual operation like `saltutil.refresh_pillar` or + # similar. Enabling this option might break pillar related functionality (e.g. pillar + # targeter). + "skip_init_pillar": bool, # Cache the GPG data to avoid having to pass through the gpg renderer "gpg_cache": bool, # GPG data cache TTL, in seconds. Has no effect unless `gpg_cache` is True @@ -1077,6 +1082,7 @@ def _gather_buffer_space(): "pillar_cache_backend": "disk", "request_channel_timeout": 60, "request_channel_tries": 3, + "skip_init_pillar": False, "gpg_cache": False, "gpg_cache_ttl": 86400, "gpg_cache_backend": "disk", diff --git a/salt/minion.py b/salt/minion.py index d2cf7c7fb966..67df8eaba4e0 100644 --- a/salt/minion.py +++ b/salt/minion.py @@ -442,13 +442,16 @@ def gen_modules(self, initial_load=False, context=None): if context is None: context = {} if initial_load: - self.opts["pillar"] = salt.pillar.get_pillar( - self.opts, - self.opts["grains"], - self.opts["id"], - self.opts["saltenv"], - pillarenv=self.opts.get("pillarenv"), - ).compile_pillar() + if self.opts.get("skip_init_pillar", False): + self.opts["pillar"] = {} + else: + self.opts["pillar"] = salt.pillar.get_pillar( + self.opts, + self.opts["grains"], + self.opts["id"], + self.opts["saltenv"], + pillarenv=self.opts.get("pillarenv"), + ).compile_pillar() self.utils = salt.loader.utils(self.opts, context=context) self.functions = salt.loader.minion_mods( @@ -1427,16 +1430,19 @@ def _post_master_init(self, master): if self.connected: self.opts["master"] = master - # Initialize pillar before loader to make pillar accessible in modules - async_pillar = salt.pillar.get_async_pillar( - self.opts, - self.opts["grains"], - self.opts["id"], - self.opts["saltenv"], - pillarenv=self.opts.get("pillarenv"), - ) - self.opts["pillar"] = yield async_pillar.compile_pillar() - async_pillar.destroy() + if self.opts.get("skip_init_pillar", False): + self.opts["pillar"] = {} + else: + # Initialize pillar before loader to make pillar accessible in modules + async_pillar = salt.pillar.get_async_pillar( + self.opts, + self.opts["grains"], + self.opts["id"], + self.opts["saltenv"], + pillarenv=self.opts.get("pillarenv"), + ) + self.opts["pillar"] = yield async_pillar.compile_pillar() + async_pillar.destroy() if not self.ready: self._setup_core() diff --git a/salt/utils/parsers.py b/salt/utils/parsers.py index 97b3e4f7667f..e05239c3025e 100644 --- a/salt/utils/parsers.py +++ b/salt/utils/parsers.py @@ -2906,6 +2906,21 @@ def _mixin_setup(self): action="store_true", help="Do not load grains.", ) + self.add_option( + "--no-skip-init-pillar", + default=True, + action="store_false", + dest="skip_init_pillar", + help=( + "Explicitly load pillar on minion startup (overrides any skip_init_pillar in /etc/salt/minion)" + ), + ) + self.add_option( + "--skip-pillars", + default=False, + action="store_true", + help=("Do not load pillars."), + ) self.add_option( "--refresh-grains-cache", default=False,