What can Ansible do that Fabric can't
Server management with Python and Fabric
The two tools Chef and Puppet  are ideally suited to administering large server landscapes, but they require considerable configuration effort. If you want to regularly execute certain commands on multiple servers, you should alternatively take a look at Fabric , an impressive Python module that manages such tasks as flexible cooking recipes.
Turning daily tasks into fabric tasks is a great help for anyone who works with different systems. These tasks can be performed with the "" command. Originally Fabric only had a few simple features, but over the years it has grown so much that in some cases it can replace Chef and Puppet.
Relies on SSH
If an SSH configuration already exists to log in to another computer, Fabric can make use of it. Of course, Fabric also works locally. Fabric can include or exclude individual hosts from specific tasks, either directly by their names or through assigned roles. Fabric can execute tasks in parallel or one after the other. For better control, Fabric always shows what it is doing if required - this helps, for example, with troubleshooting. Fabric has simple capabilities for managing files in the »« module. Fabric is easy to install using "":pip install fabric
If you don't have Pip installed, you can try Easy-Install instead:easy_install fabric
Alternatively, the installation from the source code usually works without any major problems.
If you call "", the tool looks for the file "" in the current directory or moves up the directory hierarchy until it finds such a file. In this way it is easy to manage different tasks in different directories. The task file can also be specified directly with the »« switch.
A first simple fabric task looks something like this:from fabric import * def uptime (): run (uptime)
It executes the uptime command on every computer that is listed on the command line when it is called, for example:fab -H localhost uptime
A list of all available fabric tasks shows "", but these are the so-called "old style" tasks, which include all defined functions. It is better to use the new style tasks, which only display tasks that can be used and not those that are only used for internal purposes. If you redefine the above task as follows:def uptime (): run (uptime) @task def get_uptime (): uptime ()
shows »« only »« and ignores the »« function. Listing 1 shows what the result looks like when the task is called with two hosts.
Hosts in the file
Specifying the hosts again and again on the command line is tedious in the long run. As the next example shows, they can also be defined directly in a task. It uses Fabric to deploy a website based on Git. Because the hosts are defined in the file, it is sufficient to execute "" on the command line.
First, the script uses the Python Datetime module to compose a Git tag string that reflects the deployment time.
This task should only be executed once, the decorator "" takes care of that. The "" task executes the "" task and changes to the "" directory to start the Git command there. At the end of the with block, the script automatically switches back to the previous directory and restarts the Apache web server with "". Figure 1 shows the process.
- Is there life on Europe or on Titan
- How do you blow a head gasket
- What do jack rabbits eat
- Can sound to expand the atmosphere
- Who is the POTUS mobile operator
- What are OCL expressions
- Might beat Blue Origin SpaceX
- What is 50 50x50 50 50 50x50
- What is a leak test
- How is the stock market loss calculated
- What is the most important knowledge
- Modern boats have hydrophones
- What are some big, double-meaning questions
- How do I avoid illogic and rethinking
- Should Barcelona let Fabregas go
- What is ephedrine
- Is reinforcement an addiction?
- How does the pH-value differ from the acid-alkalinity?
- What is the best direction
- How does property pass at death
- How does suitability differ from creativity
- Is the ECOWAS an instrument of EU influence
- Brahmos is a nuclear missile
- Will it help me suppress a yawn when I sleep?