Execute the batch run. Generator. For each minion return, yields ``({minion_id: ret_data}, retcode)`` (or the raw event envelope when ``raw=True``). Minion returns carrying ``failed: True`` (and ``failhard`` halt events) are recorded internally but not
(self)
| 140 | ) |
| 141 | |
| 142 | def run(self): |
| 143 | """ |
| 144 | Execute the batch run. |
| 145 | |
| 146 | Generator. For each minion return, yields |
| 147 | ``({minion_id: ret_data}, retcode)`` (or the raw event envelope |
| 148 | when ``raw=True``). Minion returns carrying ``failed: True`` |
| 149 | (and ``failhard`` halt events) are recorded internally but not |
| 150 | yielded, preserving the pre-Phase-2 yield shape. |
| 151 | """ |
| 152 | self.minions, self.ping_gen, self.down_minions = self.gather_minions() |
| 153 | |
| 154 | if not self.minions: |
| 155 | return |
| 156 | |
| 157 | batch_jid = salt.utils.jid.gen_jid(self.opts) |
| 158 | state = salt.utils.batch_state.create_batch_state( |
| 159 | self.opts, self.minions, batch_jid, driver="cli" |
| 160 | ) |
| 161 | |
| 162 | # The sync CLI driver does not write under the master's |
| 163 | # ``cachedir`` itself. ``cachedir`` is owned by the master |
| 164 | # daemon's user (typically ``salt``); the CLI is normally |
| 165 | # invoked as ``root``, so any direct write would pre-create |
| 166 | # the JID directory with the wrong ownership and trip a |
| 167 | # ``PermissionError`` in ``local_cache.prep_jid`` when the |
| 168 | # master tries to write the ``jid`` file (issue #69418). |
| 169 | # |
| 170 | # Instead, we ship every state change to the master-side |
| 171 | # ``BatchManager`` via ``salt/batch/<jid>/{new,progress, |
| 172 | # complete,halted}`` events. The manager — already running |
| 173 | # as the master daemon's user — persists ``.batch.p`` and |
| 174 | # maintains the active-batch index on the CLI's behalf. |
| 175 | # ``batch.status`` / ``batch.list_active`` / ``batch.stop`` |
| 176 | # see sync batches because of that handoff. All event ops |
| 177 | # are best-effort: if the master event bus is unreachable |
| 178 | # the CLI batch still completes correctly with no visibility. |
| 179 | self._fire_event( |
| 180 | salt.utils.batch_output.state_payload(state), |
| 181 | salt.utils.batch_output.tag_new(batch_jid), |
| 182 | ) |
| 183 | self._subscribe_to_halt(batch_jid) |
| 184 | |
| 185 | output = salt.utils.batch_output.CLIOutput(self.opts, quiet=self.quiet) |
| 186 | for down_minion in self.down_minions: |
| 187 | output.on_minion_down(down_minion) |
| 188 | |
| 189 | if self.options: |
| 190 | show_jid = self.options.show_jid |
| 191 | show_verbose = self.options.verbose |
| 192 | else: |
| 193 | show_jid = False |
| 194 | show_verbose = False |
| 195 | |
| 196 | return_value = self.opts.get("return", self.opts.get("ret", "")) |
| 197 | raw_mode = bool(self.opts.get("raw")) |
| 198 | |
| 199 | iters = [] |