-
Notifications
You must be signed in to change notification settings - Fork 86
Description
My aim is to configure a groupsource which pulls the information from an ansible inventory configuration . The benefit would be, that I only have to manage the host-inventory and groups in ansible and clustershell is able to consume those as well.
According to the docs it should be possible to
define a groupsource like:
#~/.config/clustershell/groups.conf
[myinv]
map=ansible-inventory -i myinv --graph $GROUP | perl -ne 'if (m/\|--([^@].*)/){print "$1 "}'
all=ansible-inventory -i myinv --graph all | perl -ne 'if (m/\|--([^@].*)/){print "$1 "}'
list=ansible-inventory -i myinv --graph all | perl -ne 'if (m/\|--@(.*):/){print "$1 "}'
This requires that the upcall commands are executed in the same environment as the cli-command.
But clustershell executes those commands in a subprocess.Popen
in which is sets the cwd=self.cfgdir
link. ansible-inventory
cannot find the inventory dir and fails.
The following patch works for me, but I do not know how deep this reaches and afflicts other use cases.
What do you think:
diff --git a/lib/ClusterShell/NodeUtils.py b/lib/ClusterShell/NodeUtils.py
index f4a52f6..8fcafcd 100644
--- a/lib/ClusterShell/NodeUtils.py
+++ b/lib/ClusterShell/NodeUtils.py
@@ -202,7 +202,7 @@ class UpcallGroupSource(GroupSource):
"""
cmdline = Template(self.upcalls[cmdtpl]).safe_substitute(args)
self.logger.debug("EXEC '%s'", cmdline)
- proc = Popen(cmdline, stdout=PIPE, shell=True, cwd=self.cfgdir,
+ proc = Popen(cmdline, stdout=PIPE, shell=True,
universal_newlines=True)
output = proc.communicate()[0].strip()
self.logger.debug("READ '%s'", output)
Using nodeset
or cluset
is painfully slow then, because those CLI commands tread all names as groupnames and try to resolve them in a loop, where each call to ansible-inventory
is quite slow. But clush -bg GRPNAME
works reasonable well, because there seems to be only one resolve call.