Search code examples
pythonfabric

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.


Solution

  • Try the following:

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

    or

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

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