Reputation: 12406
I am trying to write a basic Python Fabric deploy script and I have some beginner level questions.
Here is the fabfile.py
I have at the moment (modified from this example):
#!/usr/bin/env python
from fabric.api import *
import socket
import paramiko
env.roledefs = {'dev':['server.domain.tld']}
@task
@roles("dev")
def print_contents():
echo("Printing working directory contents:\n")
run("ls")
@task
@roles("dev")
def update_upgrade():
""" Update the default OS installation's basic default tools. """
sudo("sudo apt-get update")
sudo("apt-get -y upgrade")
@task
@roles("dev")
def install_memcached():
""" Download and install memcached. """
sudo("apt-get install -y memcached")
@task
@roles("dev")
def deploy():
print_contents()
# Update
update_upgrade()
# Install
install_memcached()
Questions:
import socket
and import paramiko
?print_contents()
, update_upgrade()
and install_memcached()
directly - they will only be called within the deploy()
function. Does every function need to be a task with the @task
decorator?deploy()
? Or can we use any other name for that function, eg. update_all()
?Upvotes: 1
Views: 87
Reputation: 2269
socket
and paramiko
for this script, since you are not calling them directly from your fabfile. @task
decorator is only used for functions that you would like to be available as fabric tasks on the command line. In the example you've provided, you would only need to decorate the deploy
function.When this decorator is used, it signals to Fabric that only functions wrapped in the decorator are to be loaded up as valid tasks.
More info on all of this can be found in the docs for the task decorator.
Upvotes: 1