From 21bdd8d20c35e77ff7d2fcacc4f1a0009b7bb3d2 Mon Sep 17 00:00:00 2001 From: BiloxiGeek Date: Mon, 2 Mar 2026 10:11:41 -0600 Subject: [PATCH] opt: expand short hostnames in -x when PDSH_DEFAULT_DOMAIN is set When a netgroup (-g) returns FQDNs but exclusions (-x) are specified as short hostnames, the delete silently fails because the names don't match. If PDSH_DEFAULT_DOMAIN is set, append the domain to any short hostname (no '.') in the exclusion list before attempting hostlist_delete, so short hostnames correctly match FQDNs in the working collection. --- doc/pdsh.1.in | 8 ++++++++ src/pdsh/opt.c | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/doc/pdsh.1.in b/doc/pdsh.1.in index 6c7c82b..3631c9d 100644 --- a/doc/pdsh.1.in +++ b/doc/pdsh.1.in @@ -380,6 +380,14 @@ or "-v" would increase the verbosity of ssh. (Note: these arguments are actually prepended to the ssh commandline to ensure they appear before any target hostname argument to ssh.) .TP +PDSH_DEFAULT_DOMAIN +When set, \fBpdsh\fR will append \fI.\fRDOMAIN to any short hostname +(one containing no \fI.\fR character) given to the \fI\-x\fR exclusion +option before attempting to remove it from the working collection. +This is useful when the target list (e.g. from an IPA hostgroup via +\fI\-g\fR) contains fully-qualified domain names but the exclusion list +is specified with short hostnames. +.TP WCOLL If no other node selection option is used, the WCOLL environment variable may be set to a filename from which a list of target diff --git a/src/pdsh/opt.c b/src/pdsh/opt.c index 848271f..04a0e46 100644 --- a/src/pdsh/opt.c +++ b/src/pdsh/opt.c @@ -1434,16 +1434,34 @@ static void wcoll_apply_excluded (opt_t *opt, List excludes) { ListIterator i; char *arg; + const char *domain; if (!opt->wcoll || !excludes) return; + domain = getenv ("PDSH_DEFAULT_DOMAIN"); + /* * filter explicitly excluded hosts: */ i = list_iterator_create (excludes); - while ((arg = list_next (i))) + while ((arg = list_next (i))) { hostlist_delete (opt->wcoll, arg); + /* + * If PDSH_DEFAULT_DOMAIN is set and the excluded hostname contains + * no '.' (i.e. it is a short hostname), also try to delete the + * fully-qualified form so that short hostnames in -x match FQDNs + * in the working collection (e.g. from IPA hostgroups via -g). + */ + if (domain && !strchr (arg, '.')) { + char *fqdn = NULL; + xstrcat (&fqdn, arg); + xstrcatchar (&fqdn, '.'); + xstrcat (&fqdn, (char *) domain); + hostlist_delete (opt->wcoll, fqdn); + Free ((void **) &fqdn); + } + } list_iterator_destroy (i); }