Debian Codegraph @

doc/sphinx/tools/clush.rst

raw
1 .. _clush-tool:
2
3 clush
4 -------
5
6 .. highlight:: console
7
8 *clush* is a program for executing commands in parallel on a cluster and for
9 gathering their results. It can execute commands interactively or can be used
10 within shell scripts and other applications. It is a partial front-end to the
11 :class:`.Task` class of the ClusterShell library (cf. :ref:`class-Task`).
12 *clush* currently makes use of the Ssh worker of ClusterShell by default,
13 which only requires *ssh(1)* (we tested with OpenSSH SSH client).
14
15 Some features of *clush* command line tool are:
16
17 * two modes of parallel cluster commands execution:
18
19 + :ref:`flat mode <clush-flat>`: sliding window of local or remote (e.g.
20 *ssh(1)*) commands
21 + :ref:`tree mode <clush-tree>`: commands propagated to the targets
22 through a tree of pre-configured gateways; gateways are then using a
23 sliding window of local or *ssh(1)* commands to reach the targets (if the
24 target count per gateway is greater than the
25 :ref:`fanout <clush-tree-fanout>` value)
26
27 * smart display of command results (integrated output gathering, sorting by
28 node, nodeset or node groups)
29 * standard input redirection to remote nodes
30 * files copying in parallel
31 * *pdsh* [#]_ options backward compatibility
32
33 *clush* can be started non-interactively to run a shell command, or can be
34 invoked as an interactive shell. Both modes are discussed here (see
35 :ref:`clush-oneshot` and :ref:`clush-interactive`).
36
37 Target and filter nodes
38 ^^^^^^^^^^^^^^^^^^^^^^^
39
40 *clush* offers different ways to select or filter target nodes through command
41 line options or files containing a list of hosts.
42
43 Command line options
44 """"""""""""""""""""
45
46 The ``-w`` option allows you to specify remote hosts by using ClusterShell
47 :class:`.NodeSet` syntax, including the node groups *@group* special syntax
48 (cf. :ref:`nodeset-groupsexpr`) and the Extended String Patterns syntax (see
49 :ref:`class-NodeSet-extended-patterns`) to benefit from :class:`.NodeSet`
50 basic arithmetic (like ``@Agroup&@Bgroup``). Additionally, the ``-x`` option
51 allows you to exclude nodes from remote hosts list (the same NodeSet syntax
52 can be used here). Nodes exclusion has priority over nodes addition.
53
54 Using node groups
55 """""""""""""""""
56
57 If you have ClusterShell :ref:`node groups <groups-config>` configured on your
58 cluster, any node group syntax may be used in place of nodes for ``-w`` as
59 well as ``-x``.
60
61 For example::
62
63 $ clush -w @rhel6 cat /proc/loadavg
64 node26: 0.02 0.01 0.00 1/202 23042
65
66 For *pdsh* backward compatibility, *clush* supports two ``-g`` and ``-X``
67 options to respectively select and exclude nodes group(s), but only specified
68 by omitting any *"@"* group prefix (see example below). In general, though, it
69 is advised to use the *@*-prefixed group syntax as the non-prefixed notation
70 is only recognized by *clush* but not by other tools like *nodeset*.
71
72 For example::
73
74 $ clush -g rhel6 cat /proc/loadavg
75 node26: 0.02 0.01 0.00 1/202 23033
76
77 .. _clush-all-nodes:
78
79 Selecting all nodes
80 """""""""""""""""""
81
82 The special option ``-a`` (without argument) can be used to select **all**
83 nodes, in the sense of ClusterShell node groups (see
84 :ref:`node groups configuration <groups-config>` for more details on special
85 **all** external shell command upcall). If not properly configured, the
86 ``-a`` option may lead to a runtime error like::
87
88 clush: External error: Not enough working methods (all or map + list) to get all nodes
89
90 .. _clush-pick:
91
92 Picking node(s) at random
93 """""""""""""""""""""""""
94
95 Use ``--pick`` with a maximum number of nodes you wish to pick randomly from
96 the targeted node set. **clush** will then run only on selected node(s). The
97 following example will run a script on a single random node picked from the
98 ``@compute`` group::
99
100 $ clush -w @compute --pick=1 ./nonreg-single-client-fs-io.sh
101
102 Host files
103 """"""""""
104
105 The option ``--hostfile`` (or ``--machinefile``) may be used to specify a
106 path to a file containing a list of single hosts, node sets or node groups,
107 separated by spaces and lines. It may be specified multiple times (one per
108 file).
109
110 For example::
111
112 $ clush --hostfile ./host_file -b systemctl is-enabled httpd
113
114 This option has been added as backward compatibility with other parallel shell
115 tools. Indeed, ClusterShell provides a preferred way to provision node sets
116 from node group sources and flat files to all cluster tools using
117 :class:`.NodeSet` (including *clush*). Please see :ref:`node groups
118 configuration <groups-config>`.
119
120 .. note:: Use ``--debug`` or ``-d`` to see resulting node sets from host
121 files.
122
123
124 .. _clush-flat:
125
126 Flat execution mode
127 ^^^^^^^^^^^^^^^^^^^
128
129 The default execution mode is to launch commands (local or remote) in parallel,
130 up to a certain limit fixed by the :ref:`fanout <clush-fanout>` value,
131 which is the number of child processes allowed to run at a time. This "sliding
132 window" of active commands is a common technique used on large clusters to
133 conserve resources on the initiating host, while allowing some commands to
134 time out. If used with *ssh(1)*, this does actually limit the number of
135 concurrent ssh connections.
136
137 .. _clush-fanout:
138
139 Fanout (sliding window)
140 """""""""""""""""""""""
141
142 The ``--fanout`` (or ``-f``) option of **clush** allows the user to change the
143 default *fanout* value defined in :ref:`clush.conf <clush-config>` or in the
144 :ref:`library defaults <defaults-config>` if not specified.
145
146 Indeed, it is sometimes useful to change the fanout value for a specific
147 command, for example to avoid flooding a remote service with concurrent
148 requests generated by that actual command.
149
150 The following example will launch up to ten *puppet* commands at a time on the
151 node group named *@compute*::
152
153 $ clush -w @compute -f 10 puppet agent -t
154
155 If the fanout value is set to 1, commands are executed sequentially::
156
157 $ clush -w node[40-42] -f 1 'date +%s; sleep 1'
158 node40: 1505366138
159 node41: 1505366139
160 node42: 1505366140
161
162
163 .. _clush-tree:
164
165 Tree execution mode
166 ^^^^^^^^^^^^^^^^^^^
167
168 ClusterShell's tree execution mode is a major horizontal scalability
169 improvement by providing a hierarchical command propagation scheme.
170
171 The Tree mode of ClusterShell has been the subject of `this paper`_ presented
172 at the Ottawa Linux Symposium Conference in 2012 and at the PyHPC 2013
173 workshop in Denver, USA.
174
175 The animated diagram below illustrates the hierarchical command propagation
176 principle with a head node, gateways (GW) and target nodes:
177
178 .. image:: ../_static/clush-tree-mode.svg
179 :alt: Command propagation from the head node to target nodes, directly or
180 through gateways, and results gathering back to the head node.
181 :width: 100%
182
183 The Tree mode is implemented at the library level, so that all applications
184 using ClusterShell may benefit from it. However, this section describes how
185 to use the tree mode with the **clush** command only.
186
187 .. _clush-tree-enabling:
188
189 Configuration
190 """""""""""""
191
192 The system-wide library configuration file **/etc/clustershell/topology.conf**
193 defines available/preferred routes for the command propagation tree. It is
194 recommended that all connections between parent and children nodes are carefully
195 pre-configured, for example, to avoid any SSH warnings when connecting (if
196 using the default SSH remote worker, of course).
197
198 .. highlight:: ini
199
200 The file **topology.conf** is used to define a set of routes under a
201 ``[routes]`` section. Think of it as a routing table but for cluster
202 commands. Node sets should be used when possible, for example::
203
204 [routes]
205 rio0: rio[10-13]
206 rio[10-11]: rio[100-240]
207 rio[12-13]: rio[300-440]
208
209 .. highlight:: text
210
211 The example above defines the following topology graph::
212
213 rio0
214 |- rio[10-11]
215 | `- rio[100-240]
216 `- rio[12-13]
217 `- rio[300-440]
218
219 :ref:`nodeset-groups` and :ref:`node-wildcards` are supported in
220 **topology.conf**, but any route definition with an empty node set
221 is ignored (a message is printed in debug mode in that case).
222
223 At runtime, ClusterShell will pick an initial propagation tree from this
224 topology graph definition and the current root node. Multiple admin/root
225 nodes may be defined in the file.
226
227 .. note:: The algorithm used in Tree mode does not rely on gateway system
228 hostnames anymore. In topology.conf, just use the hosts or aliases needed
229 to connect to each node.
230
231 .. highlight:: console
232
233 Enabling tree mode
234 """"""""""""""""""
235
236 Since version 1.7, the tree mode is enabled by default when a configuration
237 file is present. When the configuration file
238 **/etc/clustershell/topology.conf** exists, *clush* will use it by default for
239 target nodes that are defined there. The topology file path can be changed
240 using the ``--topology`` command line option.
241
242 .. note:: If using ``clush -d`` (debug option), clush will display an ASCII
243 representation of the initial propagation tree used. This is useful when
244 working on Tree mode configuration.
245
246 Enabling tree mode should be as transparent as possible to the end user.
247 Most **clush** options, including options defined in
248 :ref:`clush.conf <clush-config>` or specified using ``-O`` or ``-o`` (ssh
249 options) are propagated to the gateways and taken into account there.
250
251 .. _clush-tree-options:
252
253 Tree mode specific options
254 """"""""""""""""""""""""""
255
256 The ``--remote=yes|no`` command line option controls the remote execution
257 behavior:
258
259 * Default is **yes**, that will make *clush* establish connections up to the
260 leaf nodes using a *distant worker* like *ssh*.
261 * Changing it to **no** will make *clush* establish connections up to the leaf
262 parent nodes only, then the commands are executed locally on the gateways
263 (as it would be with ``--worker=exec`` on the gateways themselves).
264 This execution mode allows users to schedule remote commands on gateways
265 that take a node as an argument. On large clusters, this is useful to spread
266 the load and resources used by one-shot monitoring, IPMI, or other commands
267 on gateways. A simple example of use is::
268
269 $ clush -w node[100-199] --remote=no /usr/sbin/ipmipower -h %h-ipmi -s
270
271 This command is also valid if you don't have any tree configured, because
272 in that case, ``--remote=no`` is an alias of ``--worker=exec`` worker.
273
274 The ``--grooming`` command line option allows users to change the grooming
275 delay (float, in seconds). This feature allows gateways to aggregate responses
276 received within a certain timeframe before transmitting them back to the root
277 node in a batch fashion. This contributes to reducing the load on the root
278 node by delegating the first steps of this CPU intensive task to the gateways.
279
280 .. _clush-tree-fanout:
281
282 Fanout considerations
283 """""""""""""""""""""
284
285 ClusterShell uses a "sliding window" or *fanout* of processes to avoid too
286 many concurrent connections and to conserve resources on the initiating hosts.
287 See :ref:`clush-flat` for more details about this.
288
289 In tree mode, the same *fanout* value is used on the head node and on each
290 gateway. That is, if the *fanout* is **16**, each gateway will initiate up to
291 **16** connections to their target nodes at the same time.
292
293 .. note:: This is likely to **change** in the future, as it makes the *fanout*
294 behavior different if you are using the tree mode or not. For example,
295 some administrators are using a *fanout* value of 1 to "sequentialize" a
296 command on the cluster. In tree mode, please note that in that case, each
297 gateway will be able to run a command at the same time.
298
299 .. _clush-tree-python:
300
301 Remote Python executable
302 """"""""""""""""""""""""
303
304 You must use the same major version of Python on the gateways and the root
305 node. By default, the same python executable name as the one used on the
306 root node will be used to launch the gateways, that is, `python` or `python3`
307 (using relative path for added flexibility). You may override the selection
308 of the remote Python interpreter by defining the following environment
309 variable::
310
311 $ export CLUSTERSHELL_GW_PYTHON_EXECUTABLE=/path/to/python3
312
313 .. note:: It is highly recommended to have the same Python interpreter
314 installed on all gateways and the root node.
315
316 Debugging Tree mode
317 """""""""""""""""""
318
319 To debug Tree mode, you can define the following environment variable before
320 running **clush** (or any other applications using ClusterShell)::
321
322 $ export CLUSTERSHELL_GW_LOG_LEVEL=DEBUG (default value is INFO)
323 $ export CLUSTERSHELL_GW_LOG_DIR=/tmp (default value is /tmp)
324
325 This will generate log files of the form ``$HOSTNAME.gw.log`` in
326 ``CLUSTERSHELL_GW_LOG_DIR``.
327
328 .. _clush-oneshot:
329
330 Non-interactive (or one-shot) mode
331 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
332
333 When *clush* is started non-interactively, the command is executed on the
334 specified remote hosts in parallel (given the current *fanout* value and the
335 number of commands to execute; see *fanout* library settings in
336 :ref:`class-Task-configure`).
337
338 .. _clush-gather:
339
340 Output gathering options
341 """"""""""""""""""""""""
342
343 If option ``-b`` or ``--dshbak`` is specified, *clush* waits for command
344 completion while displaying a :ref:`progress indicator <clush-progress>` and
345 then displays gathered output results. If standard output is redirected to a
346 file, *clush* detects it and disables any progress indicator.
347
348 .. warning:: *clush* will only consolidate identical command outputs if the
349 command return codes are also the same.
350
351 The following is a simple example of *clush* command used to execute ``uname
352 -r`` on *node40*, *node41* and *node42*, wait for their completion and finally
353 display digested output results::
354
355 $ clush -b -w node[40-42] uname -r
356 ---------------
357 node[40-42]
358 ---------------
359 2.6.35.6-45.fc14.x86_64
360
361
362 It is common to cancel such command execution because a node is hung. When
363 using *pdsh* and *dshbak*, due to the pipe, all nodes output will be lost,
364 even if all nodes have successfully run the command. When you hit CTRL-C with
365 *clush*, the task is canceled but received output is not lost::
366
367 $ clush -b -w node[1-5] uname -r
368 Warning: Caught keyboard interrupt!
369 ---------------
370 node[2-4] (3)
371 ---------------
372 2.6.31.6-145.fc11
373 ---------------
374 node5
375 ---------------
376 2.6.18-164.11.1.el5
377 Keyboard interrupt (node1 did not complete).
378
379 .. note:: In standard (non-gathered) mode, *clush* prefixes each output line
380 with the name of the originating node; use the ``-N`` option to disable this
381 labeling.
382
383 .. _clush-axis:
384
385 Choosing fold axis (nD)
386 """""""""""""""""""""""
387
388 When displaying gathered results for multidimensional node sets, *clush* folds
389 the nodeset header along all *nD* axes by default. As other cluster tools
390 barely support nD nodeset syntax, the ``--axis`` option lets you fold the
391 displayed nodeset along one axis (or a few axes) only. ``--axis`` value is a set of
392 integers from 1 to n representing selected nD axes, in the form of a number or
393 a rangeset (e.g. ``1``, ``1-2``, ``1,3``); a single negative number folds along
394 the last axis whatever the number of dimensions used. Because a node set may
395 have several different dimensions, axis indices are silently truncated to fall
396 in the allowed range. For example, to gather output but fold the header along
397 the first axis only::
398
399 $ clush -b --axis=1 -w dc[1-2]n[1-2] uname -r
400 ---------------
401 dc[1-2]n1,dc[1-2]n2 (4)
402 ---------------
403 5.14.0-503.el9.x86_64
404
405 This is the per-invocation equivalent of the ``fold_axis`` library default;
406 see also the :ref:`defaults-config-slurm` of Library Defaults for changing it
407 permanently.
408
409 .. _clush-diff:
410
411 Performing *diff* of cluster-wide outputs
412 """""""""""""""""""""""""""""""""""""""""
413
414 Since version 1.6, you can use the ``--diff`` *clush* option to show
415 differences between common outputs. This feature is implemented using `Python
416 unified diff`_. This special option implies ``-b`` (gather common stdout
417 outputs) but you don't need to specify it. Example::
418
419 $ clush -w node[40-42] --diff dmidecode -s bios-version
420 --- node[40,42] (2)
421 +++ node41
422 @@ -1,1 +1,1 @@
423 -1.0.5S56
424 +1.1c
425
426 A nodeset is automatically selected as the "reference nodeset" according to
427 these criteria:
428
429 #. lowest command return code (to discard failed commands)
430 #. largest nodeset with the same output result
431 #. otherwise the first nodeset is taken (ordered (1) by name and (2) lowest range indexes)
432
433 .. _clush-outdir:
434
435 Saving output in files
436 """"""""""""""""""""""
437
438 To save the standard output (stdout) and/or error (stderr) of all remote
439 commands to local files identified with the node name in a given directory,
440 use the options ``--outdir`` and/or ``--errdir``. Any directory that
441 doesn't exist will be automatically created. These options provide a
442 similar functionality as *pssh(1)*.
443
444 For example, to save all logs from *journalctl(1)* in a local directory
445 ``/tmp/run1/stdout``, you could use::
446
447 $ clush -w node[40-42] --outdir=/tmp/run1/stdout/ journalctl >/dev/null
448
449 Standard input bindings
450 """""""""""""""""""""""
451
452 Unless the option ``--nostdin`` (or ``-n``) is specified, *clush* detects when
453 its standard input is connected to a terminal (as determined by *isatty(3)*).
454 If actually connected to a terminal, *clush* listens to standard input when
455 commands are running, waiting for an Enter key press. Doing so will display the
456 status of current nodes. If standard input is not connected to a terminal, and
457 unless the option ``--nostdin`` (or ``-n``) is specified, *clush* binds the
458 standard input of the remote commands to its own standard input, allowing
459 scripting methods like::
460
461 $ echo foo | clush -w node[40-42] -b cat
462 ---------------
463 node[40-42]
464 ---------------
465 foo
466
467 Another stdin-bound *clush* usage example::
468
469 $ ssh node10 'ls /etc/yum.repos.d/*.repo' | clush -w node[11-14] -b xargs ls
470 ---------------
471 node[11-14] (4)
472 ---------------
473 /etc/yum.repos.d/cobbler-config.repo
474
475 .. note:: Use ``--nostdin`` (or ``-n``) in the same way you would use ``ssh -n``
476 to disable standard input. Indeed, if this option is set, EOF is sent at
477 first read, as if stdin were actually connected to /dev/null.
478
479
480 .. _clush-progress:
481
482 Progress indicator
483 """"""""""""""""""
484
485 In :ref:`output gathering mode <clush-gather>`, *clush* will display a live
486 progress indicator as a simple but convenient way to follow the completion of
487 parallel commands. It can be disabled just by using the ``-q`` or ``--quiet``
488 options. The progress indicator will appear after 1 to 2 seconds and should
489 look like this::
490
491 clush: <command_completed>/<command_total>
492
493 If writing is performed to *clush* standard input, like in ``command |
494 clush``, the live progress indicator will display the global bandwidth of data
495 written to the target nodes.
496
497 Finally, the special option ``--progress`` can be used to force the display of
498 the live progress indicator. Using this option may interfere with some command
499 outputs, but it can be useful when using stdin while remote commands are
500 silent. As an example, the following command will copy a local file to
501 node[1-3] and display the global write bandwidth to the target nodes::
502
503 $ dd if=/path/to/local/file | clush -w node[1-3] --progress 'dd of=/path/to/remote/file'
504 clush: 0/3 write: 212.27 MiB/s
505
506 .. _clush-interactive:
507
508 Interactive mode
509 ^^^^^^^^^^^^^^^^
510
511 If a command is not specified, *clush* runs interactively. In this mode,
512 *clush* uses the *GNU readline* library to read command lines from the
513 terminal. *Readline* provides commands for searching through the command
514 history for lines containing a specified string. For instance, you can type
515 *Control-R* to search in the history for the next entry matching the search
516 string typed so far.
517
518 Single-character interactive commands
519 """""""""""""""""""""""""""""""""""""
520
521 *clush* also recognizes special single-character prefixes that allow the user
522 to see and modify the current nodeset (the nodes where the commands are
523 executed). These single-character interactive commands are detailed below:
524
525 +------------------------------+-----------------------------------------------+
526 | Interactive special commands | Comment |
527 +==============================+===============================================+
528 | ``clush> ?`` | show current nodeset |
529 +------------------------------+-----------------------------------------------+
530 | ``clush> +<NODESET>`` | add nodes to current nodeset |
531 +------------------------------+-----------------------------------------------+
532 | ``clush> -<NODESET>`` | remove nodes from current nodeset |
533 +------------------------------+-----------------------------------------------+
534 | ``clush> @<NODESET>`` | set current nodeset |
535 +------------------------------+-----------------------------------------------+
536 | ``clush> !<COMMAND>`` | execute ``<COMMAND>`` on the local system |
537 +------------------------------+-----------------------------------------------+
538 | ``clush> =`` | toggle the output format (gathered or |
539 | | standard mode) |
540 +------------------------------+-----------------------------------------------+
541
542 To leave an interactive session, type ``quit`` or *Control-D*. As of version
543 1.6, it is not possible to cancel a command while staying in *clush*
544 interactive session: for instance, *Control-C* is not supported and will abort
545 current *clush* interactive command (see `ticket #166`_).
546
547 Example of *clush* interactive session::
548
549 $ clush -w node[11-14] -b
550 Enter 'quit' to leave this interactive mode
551 Working with nodes: node[11-14]
552 clush> uname
553 ---------------
554 node[11-14] (4)
555 ---------------
556 Linux
557 clush> !pwd
558 LOCAL: /root
559 clush> -node[11,13]
560 Working with nodes: node[12,14]
561 clush> uname
562 ---------------
563 node[12,14] (2)
564 ---------------
565 Linux
566 clush>
567
568 The interactive mode and commands described above are subject to change and
569 improvements in future releases. Feel free to open an enhancement `ticket`_ if
570 you use the interactive mode and have some suggestions.
571
572 .. _clush-copy:
573
574 File copying mode
575 ^^^^^^^^^^^^^^^^^
576
577 When *clush* is started with the ``-c`` or ``--copy`` option, it will
578 attempt to copy specified files and/or directories to the provided cluster
579 nodes. The ``--dest`` option can be used to specify a single path where all
580 the file(s) should be copied to on the target nodes.
581 In the absence of ``--dest``, *clush* will attempt to copy each file or
582 directory found in the command line to their same location on the target
583 nodes.
584
585 Here are some examples of file copying with *clush*::
586
587 $ clush -v -w node[11-12] --copy /tmp/foo
588 `/tmp/foo' -> node[11-12]:`/tmp'
589
590 $ clush -v -w node[11-12] --copy /tmp/foo /tmp/bar
591 `/tmp/bar' -> node[11-12]:`/tmp'
592 `/tmp/foo' -> node[11-12]:`/tmp'
593
594 $ clush -v -w node[11-12] --copy /tmp/foo --dest /var/tmp/
595 `/tmp/foo' -> node[11-12]:`/var/tmp/'
596
597 .. note:: To copy a file to nodes under a different user, use the
598 ``--user=$USER`` option and **NOT** ``$USER@node[11-12]``.
599
600 Reverse file copying mode
601 ^^^^^^^^^^^^^^^^^^^^^^^^^
602
603 When *clush* is started with the ``--rcopy`` option, it will attempt to
604 retrieve specified file and/or directory from provided cluster nodes. If the
605 ``--dest`` option is specified, it must be a directory path where the files
606 will be stored with their hostname appended. If the destination path is not
607 specified, it will take each file or directory's parent directory as the
608 local destination, for example::
609
610 $ clush -v -w node[11-12] --rcopy /tmp/foo
611 node[11-12]:`/tmp/foo' -> `/tmp'
612
613 $ ls /tmp/foo.*
614 /tmp/foo.node11 /tmp/foo.node12
615
616 .. _clush-modes:
617
618 Run modes
619 ^^^^^^^^^
620
621 Since version 1.9, *clush* has support for run modes, which are special
622 :ref:`clush.conf <clush-config>` settings with a given name. See
623 :ref:`run mode configuration <clushmode-config>` for more details on how
624 to install a run mode.
625
626 This section describes how to use the run modes from the provided example
627 files. To use an installed run mode, just use the ``--mode`` or ``-m``
628 command line option followed by the mode name (e.g. ``sudo``, ``sshpass``,
629 etc.).
630
631 .. _clush-sshpass:
632
633 Run mode: sshpass
634 """""""""""""""""
635
636 Since version 1.9, *clush* has support for password-based ssh authentication.
637 It is implemented thanks to the external `sshpass`_ tool and provided sshpass run
638 mode example. When using this run mode, you will be prompted for a password
639 that will be forwarded to sshpass. This could be convenient for example in a
640 new environment to install ssh keys on a large number of servers.
641
642 Make sure you have *sshpass(1)* installed on your operating system and install
643 the sshpass run mode by creating ``sshpass.conf`` in ``clush.conf.d``::
644
645 $ cd /etc/clustershell/clush.conf.d # or $CLUSTERSHELL_CFGDIR/clush.conf.d
646 $ cp sshpass.conf.example sshpass.conf
647
648 Then, run *clush* with ``--mode=sshpass`` (or ``-m sshpass``) to activate this
649 run mode. You will be prompted for a password that will be forwarded on stdin
650 to sshpass to authenticate your ssh workers.
651
652 The following example shows how to check the date on four servers with
653 password-based ssh authentication::
654
655 $ clush -w n[1-2]c[01-02] --mode=sshpass -b date
656 Password:
657 ---------------
658 n[1-2]c[01-02] (4)
659 ---------------
660 Thu Nov 17 16:08:04 PST 2022
661
662 The following example shows how to install an ``authorized_keys`` file with
663 the :ref:`clush-copy` and password-based ssh authentication on four nodes::
664
665 $ clush -w n[1-2]c[01-02] -m sshpass -v --copy ~/authorized_keys --dest ~/.ssh/authorized_keys
666 [sshpass] run mode activated
667 [sshpass] password prompt enabled
668 Password:
669 `/home/user/authorized_keys' -> n[1-2]c[01-02]:`/home/user/.ssh/authorized_keys'
670
671 .. _clush-sudo:
672
673 Run mode: sudo
674 """"""""""""""
675
676 Since version 1.9, *clush* has support for `sudo`_ password forwarding over
677 stdin. This may be useful in an environment that only allows sysadmins
678 to perform interactive *sudo* work with password.
679
680 .. warning:: In this section, it is assumed that *sudo* always requires a
681 password for the user on the target nodes. If *sudo* does NOT require
682 any password (i.e. **NOPASSWD** is specified in your sudoers file), you
683 do not need any extra options to run your *sudo* commands with *clush*.
684
685 Make sure you have *sudo(8)* installed on your operating system. Then install
686 the sudo run mode by creating ``sudo.conf`` in ``clush.conf.d``::
687
688 $ cd /etc/clustershell/clush.conf.d # or $CLUSTERSHELL_CFGDIR/clush.conf.d
689 $ cp sudo.conf.example sudo.conf
690
691 Then, run *clush* with ``--mode=sudo`` (or ``-m sudo``) to **enable a password
692 prompt** to type your *sudo* password, then *sudo* (well, the ``command_prefix``
693 from the sudo run mode – see below) will be used to run your commands on the
694 target nodes. The password is broadcasted to all target nodes over *ssh(1)* (or
695 via your :ref:`favorite worker <clush-worker>`) and as such, must be the same
696 on all target nodes. It is not stored on disk at any time and only kept in
697 memory during the duration of the *clush* command. Thus, the password will be
698 prompted every time you run *clush*. When you start *clush* in
699 :ref:`interactive mode <clush-interactive>` along with ``--mode=sudo``, you can
700 run multiple commands in that mode without having to type your password every
701 time.
702
703 When ``--mode=sudo`` is used, *clush* will run *sudo* for you on each target
704 node, so your command itself should NOT start with ``sudo``. The actual *sudo*
705 command used by *clush* can be changed in ``clush.conf.d/sudo.conf`` or
706 in command line using ``-O command_prefix"..."``. The configured
707 ``command_prefix`` must be able to read a password on stdin followed by a new
708 line (which is what ``sudo -S`` does).
709
710 Usage example::
711
712 $ clush -w n[1-2]c[01-02] --mode=sudo -b id
713 Password:
714 ---------------
715 n[1-2]c[01-02] (4)
716 ---------------
717 uid=0(root) gid=0(root) groups=0(root)
718
719 Other options
720 ^^^^^^^^^^^^^
721
722 Overriding clush.conf settings
723 """"""""""""""""""""""""""""""
724
725 *clush* default settings are found in a configuration described in
726 :ref:`clush configuration <clush-config>`. To override any settings, use the
727 ``--option`` command line option (or ``-O`` for the shorter version), and
728 repeat as needed. Here is a simple example to disable the use of colors in the
729 output nodeset header::
730
731 $ clush -O color=never -w node[11-12] -b echo ok
732 ---------------
733 node[11-12] (2)
734 ---------------
735 ok
736
737 NO_COLOR, CLICOLOR_FORCE and CLICOLOR environment variables can also
738 be used to change the way *clush* uses colors to display messages.
739
740 .. _clush-worker:
741
742 Worker selection
743 """"""""""""""""
744
745 By default, *clush* is using the default library worker configuration when
746 running commands or copying files. In most cases, this is *ssh* (See
747 :ref:`task-default-worker` for default worker selection).
748
749 Worker selection can be performed at runtime thanks to ``--worker`` command
750 line option (or ``-R`` for the shorter version in order to be compatible with
751 *pdsh* remote command selection option)::
752
753 $ clush -w node[11-12] --worker=rsh echo ok
754 node11: ok
755 node12: ok
756
757 By default, ClusterShell supports the following worker identifiers:
758
759 * **exec**: this local worker supports parallel command execution, doesn't
760 rely on any external tool and provides command line placeholders described
761 below:
762
763 * ``%h`` and ``%host`` are substituted with each *target hostname*
764 * ``%hosts`` is substituted with the full *target nodeset*
765 * ``%n`` and ``%rank`` are substituted with the remote *rank* (0 to n-1)
766
767 For example, the following would request the exec worker to locally run
768 multiple *ipmitool* commands across the hosts foo[0-10] and automatically
769 aggregate output results (-b)::
770
771 $ clush -R exec -w foo[0-10] -b ipmitool -H %h-ipmi chassis power status
772 ---------------
773 foo[0-10] (11)
774 ---------------
775 Chassis Power is on
776
777 * **rsh**: remote worker based on *rsh*
778 * **ssh**: remote worker based on *ssh* (default)
779 * **pdsh**: remote worker based on *pdsh* that requires *pdsh* to be
780 installed; doesn't provide write support (e.g. you cannot ``cat file | clush
781 --worker pdsh``); it is primarily a 1-to-n worker example.
782
783 Worker modules distributed outside of ClusterShell are also supported by
784 specifying the case-sensitive full Python module name of a worker module.
785
786
787
788 .. [#] LLNL parallel remote shell utility
789 (https://software.llnl.gov/repo/#!/chaos/pdsh)
790
791 .. _Python unified diff:
792 https://docs.python.org/3/library/difflib.html#difflib.unified_diff
793
794 .. _ticket #166: https://github.com/clustershell/clustershell/issues/166
795 .. _ticket: https://github.com/clustershell/clustershell/issues/new
796
797 .. _this paper: https://www.kernel.org/doc/ols/2012/ols2012-thiell.pdf
798
799 .. _sshpass: http://sshpass.sourceforge.net/
800 .. _sudo: https://www.sudo.ws/