Skip to content

Commit 06fac8d

Browse files
committed
Add CLI flags for Choria transport options
Add CLI flags for all Choria transport options so they can be passed on the command line. CLI flags use a choria- prefix for clarity (e.g., --choria-config-file, --choria-ssl-ca) while internal option keys remain unprefixed so inventory files stay clean (e.g., choria: { config-file: /path }). Rename choria-agent to task-agent since it only applies to task execution. The CLI flag becomes --choria-task-agent. New CLI flags: --choria-task-agent, --choria-config-file, --choria-ssl-ca, --choria-ssl-cert, --choria-ssl-key, --choria-collective, --choria-puppet-environment, --choria-rpc-timeout, --choria-task-timeout, --choria-command-timeout, --nats-servers, --nats-connection-timeout The nats-* flags are not prefixed since they are already clearly Choria-specific. Shared options (cleanup, tmpdir, host, interpreters) are unchanged.
1 parent 683a3ca commit 06fac8d

13 files changed

Lines changed: 150 additions & 90 deletions

File tree

docs/choria-transport-dev.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ One second provides reasonable responsiveness without excessive polling.
359359

360360
### Deterministic agent selection
361361

362-
Agent selection for `run_task` is explicit via the `choria-agent` config
362+
Agent selection for `run_task` is explicit via the `task-agent` config
363363
option (default `bolt_tasks`). There is no automatic fallback between agents.
364364
If the selected agent is not available on a target, that target gets a clear
365365
error. This is simpler and more predictable than a try-and-fallback approach.

docs/choria-transport-plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ What shipped:
123123
cleanup
124124
- `run_task` via shell agent with support for all input methods (environment,
125125
stdin, both)
126-
- Deterministic agent selection via `choria-agent` config and `--choria-agent`
126+
- Deterministic agent selection via `task-agent` config and `--choria-task-agent`
127127
CLI flag (no automatic fallback between agents)
128128
- Batched shell polling via `shell.list` + `shell.statuses` for scalability
129129
- Platform-aware command builders for POSIX and Windows (PowerShell)

docs/choria-transport-testing.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ bolt_tasks agent to download. The server-side module paths are listed first
163163
so that OpenBolt reads the same module versions that the bolt_tasks agent will
164164
actually download from the server. The local `modules` directory comes last
165165
as a fallback for Puppetfile-installed dependencies. When using
166-
`--choria-agent shell`, OpenBolt uploads files directly, so local modules should
166+
`--choria-task-agent shell`, OpenBolt uploads files directly, so local modules should
167167
take precedence instead — put `modules` first or omit the server paths.
168168

169169
Task helper dependencies like `puppetlabs-ruby_task_helper` must also be
@@ -483,10 +483,10 @@ Expected: Still fails with the shell agent error.
483483

484484
```bash
485485
# Force bolt_tasks (should work, same as default)
486-
bolt task run facts --targets nodeA.example.com --choria-agent bolt_tasks
486+
bolt task run facts --targets nodeA.example.com --choria-task-agent bolt_tasks
487487
488488
# Force shell (should fail: not installed)
489-
bolt task run facts --targets nodeA.example.com --choria-agent shell
489+
bolt task run facts --targets nodeA.example.com --choria-task-agent shell
490490
```
491491

492492
Expected: First succeeds (or fails at download, not at agent detection).
@@ -553,7 +553,7 @@ default and both nodes have it.
553553
**run_task with local task (not on OpenVox/Puppet Server)**
554554

555555
Test with a task that's NOT on the OpenVox/Puppet Server (a local custom task).
556-
Without `--choria-agent shell`, this will fail because bolt_tasks can't find
556+
Without `--choria-task-agent shell`, this will fail because bolt_tasks can't find
557557
the task on the OpenVox/Puppet Server:
558558

559559
```bash
@@ -570,12 +570,12 @@ bolt task run choria_test::hello --targets nodeA.example.com
570570
```
571571

572572
Expected: Fails with `bolt/choria-task-download-failed` and a message
573-
suggesting `--choria-agent shell`.
573+
suggesting `--choria-task-agent shell`.
574574

575-
Now retry with `--choria-agent shell` (Node A has the shell agent):
575+
Now retry with `--choria-task-agent shell` (Node A has the shell agent):
576576

577577
```bash
578-
bolt task run choria_test::hello --targets nodeA.example.com --choria-agent shell
578+
bolt task run choria_test::hello --targets nodeA.example.com --choria-task-agent shell
579579
```
580580

581581
Expected: Succeeds via the shell agent.
@@ -584,10 +584,10 @@ Expected: Succeeds via the shell agent.
584584

585585
```bash
586586
# Use shell agent (Node A has it)
587-
bolt task run choria_test::hello --targets nodeA.example.com --choria-agent shell
587+
bolt task run choria_test::hello --targets nodeA.example.com --choria-task-agent shell
588588
589589
# Use shell agent (Node B doesn't have it)
590-
bolt task run choria_test::hello --targets nodeB.example.com --choria-agent shell
590+
bolt task run choria_test::hello --targets nodeB.example.com --choria-task-agent shell
591591
```
592592

593593
Expected:
@@ -605,7 +605,7 @@ have both agents installed.
605605
bolt command run 'whoami' --targets nodeA.example.com,nodeB.example.com
606606
bolt script run /tmp/test_script.sh --targets nodeA.example.com,nodeB.example.com
607607
bolt task run facts --targets nodeA.example.com,nodeB.example.com
608-
bolt task run choria_test::hello --targets nodeA.example.com,nodeB.example.com --choria-agent shell
608+
bolt task run choria_test::hello --targets nodeA.example.com,nodeB.example.com --choria-task-agent shell
609609
```
610610

611611
All should succeed on both nodes.
@@ -728,7 +728,7 @@ OpenBolt caches agent lists per target for the transport's lifetime. Start a fre
728728
|-------------|----------------|-----------------|---------------------------|--------------------------------------|
729729
| run_command | agent error | agent error | works | works (shell) |
730730
| run_script | agent error | agent error | works | works (shell) |
731-
| run_task | no-agent error | works (bt) | works (--choria-agent sh) | works (bt default, sh if configured) |
731+
| run_task | no-agent error | works (bt) | works (--choria-task-agent sh) | works (bt default, sh if configured) |
732732
| upload | unsupported | unsupported | unsupported | unsupported |
733733
| download | unsupported | unsupported | unsupported | unsupported |
734734
| connected? | works | works | works | works |

docs/choria-transport.md

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,37 @@ targets:
8686

8787
### Config option reference
8888

89-
| Option | Type | Default | Description |
90-
|--------|------|---------|-------------|
91-
| `choria-agent` | String | `bolt_tasks` | Agent for task execution: `bolt_tasks` or `shell`. Also available as `--choria-agent` CLI flag. |
92-
| `cleanup` | Boolean | `true` | Clean up temp directories after operations. Set to `false` for debugging. |
93-
| `collective` | String | (from Choria config file) | Choria collective to route messages through. Per-target. |
94-
| `command-timeout` | Integer | `60` | Seconds to wait for commands and scripts to complete. |
95-
| `config-file` | String | (auto-detected) | Path to a Choria/MCollective client config file. |
96-
| `host` | String | (from URI) | Target's Choria identity (FQDN). Overrides the hostname from the URI. |
97-
| `interpreters` | Hash | (none) | File extension to interpreter mapping (e.g., `{".rb": "/usr/bin/ruby"}`). |
98-
| `nats-connection-timeout` | Integer | `30` | Seconds to wait for the TCP connection to the NATS broker. |
99-
| `nats-servers` | String or Array | (from Choria config file) | NATS broker addresses. Overrides the config file. |
100-
| `puppet-environment` | String | `production` | Puppet environment for bolt_tasks file URIs. |
101-
| `rpc-timeout` | Integer | `30` | Seconds to wait for replies to individual RPC calls. |
102-
| `ssl-ca` | String | (from Choria config file) | CA certificate path for TLS. |
103-
| `ssl-cert` | String | (from Choria config file) | Client certificate path for TLS. |
104-
| `ssl-key` | String | (from Choria config file) | Client private key path for TLS. |
105-
| `task-timeout` | Integer | `300` | Seconds to wait for task execution to complete. |
106-
| `tmpdir` | String | `/tmp` or `C:\Windows\Temp` | Base path for temp directories on remote nodes. Must be absolute. |
89+
| Option | CLI Flag | Type | Default | Description |
90+
|--------|----------|------|---------|-------------|
91+
| `task-agent` | `--choria-task-agent` | String | `bolt_tasks` | Agent for task execution: `bolt_tasks` or `shell`. |
92+
| `cleanup` | `--cleanup` | Boolean | `true` | Clean up temp directories after operations. Set to `false` for debugging. |
93+
| `collective` | `--choria-collective` | String | (from config file) | Choria collective to route messages through. Per-target. |
94+
| `command-timeout` | `--choria-command-timeout` | Integer | `60` | Seconds to wait for commands and scripts to complete. |
95+
| `config-file` | `--choria-config-file` | String | (auto-detected) | Path to a Choria/MCollective client config file. |
96+
| `host` | | String | (from URI) | Target's Choria identity (FQDN). Overrides the hostname from the URI. |
97+
| `interpreters` | | Hash | (none) | File extension to interpreter mapping (e.g., `{".rb": "/usr/bin/ruby"}`). |
98+
| `nats-connection-timeout` | `--nats-connection-timeout` | Integer | `30` | Seconds to wait for the TCP connection to the NATS broker. |
99+
| `nats-servers` | `--nats-servers` | String or Array | (from config file) | NATS broker addresses in `nats://host:port` format (comma-separated for multiple). Multiple servers provide failover if a broker is unavailable. Overrides the config file. |
100+
| `puppet-environment` | `--choria-puppet-environment` | String | `production` | Puppet environment for bolt_tasks file URIs. |
101+
| `rpc-timeout` | `--choria-rpc-timeout` | Integer | `30` | Seconds to wait for replies to individual RPC calls. |
102+
| `ssl-ca` | `--choria-ssl-ca` | String | (from config file) | CA certificate path for TLS. |
103+
| `ssl-cert` | `--choria-ssl-cert` | String | (from config file) | Client certificate path for TLS. |
104+
| `ssl-key` | `--choria-ssl-key` | String | (from config file) | Client private key path for TLS. |
105+
| `task-timeout` | `--choria-task-timeout` | Integer | `300` | Seconds to wait for task execution to complete. |
106+
| `tmpdir` | `--tmpdir` | String | `/tmp` or `C:\Windows\Temp` | Base path for temp directories on remote nodes. Must be absolute. |
107+
108+
**CLI flag precedence:** CLI flags provide default values that can be
109+
overridden by inventory-level config (per-group or per-target). For example,
110+
if a target has `collective: staging` in its inventory entry and
111+
`--choria-collective production` is passed on the CLI, the inventory value
112+
wins. For ad-hoc targets specified via `--targets` that aren't defined in an
113+
inventory file, CLI flags take full effect.
114+
115+
For options that have corresponding values in the Choria config file
116+
(`nats-servers`, `ssl-ca`/`ssl-cert`/`ssl-key`, and `collective`), the full
117+
precedence from lowest to highest is: Choria config file < CLI flags <
118+
inventory. All other options use OpenBolt-level defaults and are not affected by
119+
the Choria config file.
107120

108121
**Timeout hierarchy:** Three levels of timeout control different things:
109122
- `nats-connection-timeout` (30s): How long to wait for the initial TCP
@@ -160,7 +173,7 @@ Works with either the **bolt_tasks** or **shell** agent.
160173
bolt task run facts --targets node1.example.com
161174
162175
# Use shell agent for local tasks not on the OpenVox/Puppet Server
163-
bolt task run my_project::check --targets node1.example.com --choria-agent shell
176+
bolt task run my_project::check --targets node1.example.com --choria-task-agent shell
164177
```
165178

166179
Agent selection is deterministic with no automatic fallback. If the selected
@@ -198,7 +211,7 @@ installed on target nodes.
198211
With the shell agent:
199212
- `run_command` and `run_script` work
200213
- `run_task` can use either agent (bolt_tasks by default, or shell with
201-
`--choria-agent shell`)
214+
`--choria-task-agent shell`)
202215

203216
The shell agent DDL (required by the client library) is bundled with OpenBolt
204217
and loaded automatically. No client-side setup is needed.
@@ -270,8 +283,8 @@ modulepath:
270283

271284
Server-side paths are listed first so that OpenBolt reads the same module versions
272285
that the bolt_tasks agent will download from the server. When using
273-
`--choria-agent shell`, OpenBolt uploads task files directly, so local modules
274-
should take precedence instead put `modules` first or omit the server paths.
286+
`--choria-task-agent shell`, OpenBolt uploads task files directly, so local modules
287+
should take precedence instead -- put `modules` first or omit the server paths.
275288

276289
OpenBolt also auto-injects its own internal paths (visible in `--log-level debug`
277290
output): `bolt-modules` is prepended, and `.modules` plus the gem's built-in
@@ -308,22 +321,22 @@ bolt/choria-task-download-failed: ... ruby_task_helper/files/task_helper.rb: 404
308321
### Using the shell agent for tasks
309322

310323
If a task is not available on the OpenVox/Puppet Server (e.g., it's a local project
311-
task), set `choria-agent` to `shell` to upload and execute it directly via
324+
task), set `task-agent` to `shell` to upload and execute it directly via
312325
the shell agent, bypassing the OpenVox/Puppet Server entirely:
313326

314327
```yaml
315328
# bolt-project.yaml
316329
choria:
317-
choria-agent: shell
330+
task-agent: shell
318331
```
319332

320333
Or per-invocation:
321334

322335
```bash
323-
bolt task run my_project::check --targets node1 --choria-agent shell
336+
bolt task run my_project::check --targets node1 --choria-task-agent shell
324337
```
325338

326-
When using `--choria-agent shell`, the OpenVox/Puppet Server requirement is bypassed
339+
When using `--choria-task-agent shell`, the OpenVox/Puppet Server requirement is bypassed
327340
entirely. OpenBolt uploads task files directly via the shell agent, so only the
328341
local modulepath matters.
329342

@@ -338,7 +351,7 @@ local modulepath matters.
338351

339352
3. **bolt_tasks requires an OpenVox/Puppet Server.** The bolt_tasks agent downloads
340353
task files from the OpenVox/Puppet Server. Tasks not served by the OpenVox/Puppet Server
341-
will fail with an error suggesting `--choria-agent shell`.
354+
will fail with an error suggesting `--choria-task-agent shell`.
342355

343356
4. **No streaming output.** All output is returned on completion, not streamed
344357
incrementally.
@@ -354,7 +367,7 @@ local modulepath matters.
354367
after OpenBolt reports a timeout (bolt_tasks has no kill mechanism).
355368

356369
8. **File size limit for shell agent uploads.** When using the shell agent
357-
(`run_script`, `run_task` with `--choria-agent shell`), files are
370+
(`run_script`, `run_task` with `--choria-task-agent shell`), files are
358371
base64-encoded and sent as RPC messages. The maximum file size is limited
359372
by the NATS max message size (default 1MB, roughly 750KB effective after
360373
base64 overhead). Increase `plugin.choria.network.client_max_payload` in

lib/bolt/bolt_option_parser.rb

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ class BoltOptionParser < OptionParser
1313
run_context: %w[concurrency inventoryfile save-rerun cleanup puppetdb],
1414
global_config_setters: PROJECT_PATHS + %w[modulepath],
1515
transports: %w[transport connect-timeout tty native-ssh ssh-command copy-command],
16+
choria: %w[config-file ssl-ca ssl-cert ssl-key collective
17+
puppet-environment rpc-timeout task-timeout command-timeout
18+
nats-servers nats-connection-timeout],
1619
display: %w[format color verbose trace stream],
1720
global: %w[help version log-level clear-cache] }.freeze
1821

@@ -168,7 +171,7 @@ def get_help_text(subcommand, action = nil)
168171
when 'task'
169172
case action
170173
when 'run'
171-
{ flags: ACTION_OPTS + %w[params tmpdir noop choria-agent],
174+
{ flags: ACTION_OPTS + %w[params tmpdir noop task-agent],
172175
banner: TASK_RUN_HELP }
173176
when 'show'
174177
{ flags: OPTIONS[:global] + OPTIONS[:global_config_setters] + %w[filter format],
@@ -1095,10 +1098,54 @@ def initialize(options)
10951098
define('--tmpdir DIR', 'The directory to upload and execute temporary files on the target.') do |tmpdir|
10961099
@options[:tmpdir] = tmpdir
10971100
end
1098-
define('--choria-agent AGENT', %w[bolt_tasks shell],
1101+
define('--choria-task-agent AGENT', %w[bolt_tasks shell],
10991102
"Which Choria agent to use for task execution (bolt_tasks, shell).",
11001103
"Defaults to 'bolt_tasks'. Set to 'shell' for tasks not on the Puppet Server.") do |agent|
1101-
@options[:'choria-agent'] = agent
1104+
@options[:'task-agent'] = agent
1105+
end
1106+
define('--choria-config-file PATH',
1107+
'Path to a Choria/MCollective client configuration file.') do |path|
1108+
@options[:'config-file'] = path
1109+
end
1110+
define('--choria-ssl-ca PATH',
1111+
'CA certificate path for Choria TLS authentication.') do |path|
1112+
@options[:'ssl-ca'] = path
1113+
end
1114+
define('--choria-ssl-cert PATH',
1115+
'Client certificate path for Choria TLS authentication.') do |path|
1116+
@options[:'ssl-cert'] = path
1117+
end
1118+
define('--choria-ssl-key PATH',
1119+
'Client private key path for Choria TLS authentication.') do |path|
1120+
@options[:'ssl-key'] = path
1121+
end
1122+
define('--choria-collective NAME',
1123+
'Choria collective to route messages through.') do |name|
1124+
@options[:collective] = name
1125+
end
1126+
define('--choria-puppet-environment ENV',
1127+
"Puppet environment for bolt_tasks file downloads (default: 'production').") do |env|
1128+
@options[:'puppet-environment'] = env
1129+
end
1130+
define('--choria-rpc-timeout SECONDS', Integer,
1131+
'Seconds to wait for replies to individual Choria RPC calls (default: 30).') do |timeout|
1132+
@options[:'rpc-timeout'] = timeout
1133+
end
1134+
define('--choria-task-timeout SECONDS', Integer,
1135+
'Seconds to wait for task execution to complete (default: 300).') do |timeout|
1136+
@options[:'task-timeout'] = timeout
1137+
end
1138+
define('--choria-command-timeout SECONDS', Integer,
1139+
'Seconds to wait for commands and scripts to complete (default: 60).') do |timeout|
1140+
@options[:'command-timeout'] = timeout
1141+
end
1142+
define('--nats-servers SERVERS',
1143+
'NATS broker addresses in nats://host:port format (comma-separated for multiple).') do |servers|
1144+
@options[:'nats-servers'] = servers
1145+
end
1146+
define('--nats-connection-timeout SECONDS', Integer,
1147+
'Seconds to wait for the TCP connection to the NATS broker (default: 30).') do |timeout|
1148+
@options[:'nats-connection-timeout'] = timeout
11021149
end
11031150

11041151
separator "\n#{self.class.colorize(:cyan, 'Module options')}"

lib/bolt/config/transport/choria.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class Config
88
module Transport
99
class Choria < Base
1010
OPTIONS = %w[
11-
choria-agent
1211
cleanup
1312
collective
1413
command-timeout
@@ -22,6 +21,7 @@ class Choria < Base
2221
ssl-ca
2322
ssl-cert
2423
ssl-key
24+
task-agent
2525
task-timeout
2626
tmpdir
2727
].sort.freeze
@@ -41,9 +41,9 @@ class Choria < Base
4141
private def validate
4242
super
4343

44-
if @config['choria-agent'] && !VALID_AGENTS.include?(@config['choria-agent'])
44+
if @config['task-agent'] && !VALID_AGENTS.include?(@config['task-agent'])
4545
raise Bolt::ValidationError,
46-
"choria-agent must be one of #{VALID_AGENTS.join(', ')}, got '#{@config['choria-agent']}'"
46+
"task-agent must be one of #{VALID_AGENTS.join(', ')}, got '#{@config['task-agent']}'"
4747
end
4848

4949
if @config['tmpdir'] && !absolute_path?(@config['tmpdir'])

lib/bolt/config/transport/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Options
5151
_default: true,
5252
_example: false
5353
},
54-
"choria-agent" => {
54+
"task-agent" => {
5555
type: String,
5656
description: "Which Choria agent to use for task execution. Defaults to 'bolt_tasks' " \
5757
"(downloads task files from a Puppet Server). Set to 'shell' for tasks " \

0 commit comments

Comments
 (0)