June 2018
Intermediate to advanced
398 pages
9h
English
In our first Fabric script, fabfile_first.py, we have a task that prompts the user for the directory, then switches to it and prints its content. This is done by using ;, which appends two Linux commands together. However, running the same won't always work on other operating systems. That's where the Fabric context manager comes into the picture.
The context manager maintains the directory state when executing commands. It usually runs with Python by using with-statement, and, inside the block, you can write any of the previous Fabric operations. Let's look at an example to explain the idea:
from fabric.api import *from fabric.context_managers import *env.hosts = [ '10.10.10.140', # ubuntu machine '10.10.10.193'
Read now
Unlock full access