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:
- Do I need
import socketandimport paramiko? - I do not plan to call functions
print_contents(),update_upgrade()andinstall_memcached()directly - they will only be called within thedeploy()function. Does every function need to be a task with the@taskdecorator? - Since this is a Fabric deploy script, does the final task need to be called
deploy()? Or can we use any other name for that function, eg.update_all()?