elderusr07 elderusr07 - 1 year ago 49
Python Question

Passing a Variable to Fabric?

Trying to figure out how to pass a variable to fabric but having issues:

def installpatch(install):
sudo("apt-get install %s") % install

However when passing trying to execute this via CLI, it shows up as the below:

user@linux: fab installpatch:vi
Fatal error: sudo() received nonzero return code 100 while executing!
Requested: apt-get install %s
Executed: sudo -S -p 'sudo password:' /bin/bash -l -c "apt-get install %s"

Entering it as

fab installpatch:'vi'

makes no difference. Any suggestions? I'm assuming I'm just missing something super simple.

Goal: Be able to create a fabric command that allows me to pass a variable/name to it to install a specific piece of software on multiple PCs.

Answer Source

Try the following:

sudo(("apt-get install %s") % install)


sudo("apt-get install {}".format(install))

The % operator in your question works only when combined with a string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download