You may remember my recent article about running commands across a number of hosts with SSH and BASH. Then there was my second review of Fabric, where I mention my ‘dream’ to write a similar system in BASH some day. I’m slowly getting better with BASH and recently I’ve been working on mastering redirection and sub-shells. Well I’ve got another nice parlor trick to share with you!
Months ago I was just getting my feet wet with Fabric and Python. Python is a pleasant language, I’m not sure how much I’ll do with it, but I’m happy to have ramped up on the basics. Fabric is nice too. Some of my original thoughts about designing my Python/Fabric setup have changed a bit over the past few months to reflect lessons from practical experience.
Today working with Fabric I found myself wondering if there is any way to pass a hash to a Fabric task. The reason being I didn’t know how many arguments I’d need to pass to a particular task during a given invocation. Fabric supports passing named arguments to task functions, turns out, it also supports variable arguments.
I’ve been using Fabric for a couple of months now. Before that I took a quick look at Capistrano. Sometimes I have a simple task I want to do on a few servers, and I don’t feel like touching either one of them. We’re talking about those times where you’d almost rather login to every box and run the commands by hand. Good news is before there was Python or Ruby, there was BASH!
Since I’ve been using Fabric for over a month now, and working with BASH a lot lately, I realized one reason why Fabric might be slower than alternatives like MCollective and pexpect. Fabric executes each run invocation through a separate ssh connection. By combining a set of run calls into a single command and one run call, the same Fabric script can run much faster.