[PYTHON] I was in charge of maintaining the Fabric script, but I don't know.> <To those who

I was given a pre-built Fabric script, but ... I don't know what I'm doing ...> < Because it was, I summarized the words that appear frequently.

If you don't have an existing script in the first place I wonder if I can understand it naturally by looking at the tutorial from the beginning.

By the way, the official tutorial http://fabric-ja.readthedocs.org/ja/latest/tutorial.html

env It is called an environment dictionary in'** env ** ironment'. It's a so-called configuration file, Rather than a configuration file ** A dictionary object that can be referenced globally in a script ** It is a correct recognition. It's a dictionary, but you can access it like an attribute with env.hosts for ease of use.

It's the most important element in Fabric that is used for anything.

By the way, there is a function called settings (), but if you use it with the with clause, The effect is that only that scope can be set to a specific setting.

from fabric.api import settings

def hoge():
  with settings(warn_only=True):
    return run('hoge hoge')

Is env.warn_only = False by default only in the with clause scope warn_only = True. It seems like you'll find a special meaning in settings when using Django, but that's it for Fabric.

local () and run ()

local () is local. In other words, execute the command locally on the running PC. Run (), on the other hand, executes the command in the target's remote environment. If you are doing something like local ('cd / path / mypath') in run ()

Skip the run () process from your PC to the remote PC ↓ Remote PC moves directory to cd / path / mypath to its local

It's like that. There is also sudo (), which is run by sudo.

role Don't be fooled by the translation of role. It's just a grouping of hosts. It is set in env.roledefs.

env.roledefs = {
  'web-servers': ['web1', 'web2']
}

This targets web1 and web2 servers when deploying to a web server, Rather than doing ['web1','web2'] every time, it would be easier if you could just specify'web-servers'. There is no more meaning than that. If the role key has the same name as the command name, Fabric beginners will not understand it, If you calm down, this is all.

By the way, it can also be used with decorators,

@role('web-servers')
def deploy():
  '''do deploy'''

If so, the command will be executed for the role.

task decorator

@taskWhen applied to a function with ** "This is a feasible task" ** Fabric will pick it up. That is, it will be listed in $ fab -l. It's a relatively new feature, so if you use this decorator Note that functions without ** @ task``` will not appear in `$ fab -l``` **.

I purposely used the task decorator because it also has a task () function, but I have no chance to use it directly. There is almost no such thing, so you don't have to worry about it.

execute The meaning of run and local is slightly confusing, but ** Call the Fabric task function from another task function. ** ** In other words, processing can be nested. The difference from making a normal function call is ** The host and role settings for each task are applied as they are ** There is in. So you can intuitively nest tasks without thinking about the details. As a usage, for example

--Deploy --Get the latest source code --Server restart

If there was a task function for each of

def deploy()
  execute(Get the latest source code)
  execute(Server restart)

You should be doing something like that.


Suddenly I was given a pre-built script and looked at the contents, but I don't understand! It was a vocabulary that seemed to be. The official documentation should be easier to understand if these alone make sense!

Recommended Posts

I was in charge of maintaining the Fabric script, but I don't know.> <To those who
I want to know the population of each country in the world.
Hello, Flask! Can be done in seconds, but people who don't know the contents
The first step for those who are amateurs of statistics but want to implement machine learning models in Python
I tried to create a Python script to get the value of a cell in Microsoft Excel
I want to know the features of Python and pip
I want to know the legend of the IT technology world
For those of you who don't know how to set a password with Jupyter on Docker
How to know the internal structure of an object in Python
I wrote the code to write the code of Brainf * ck in python
I don't know the value error
[Fabric] I was addicted to using boolean as an argument, so make a note of the countermeasures.
I don't want to admit it ... The dynamical representation of Neural Networks
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I analyzed Airbnb data for those who want to stay in Amsterdam
I want to sort a list in the order of other lists
The file name was bad in Python and I was addicted to import
I want to analyze the emotions of people who want to meet and tremble
I want to leave an arbitrary command in the command history of Shell
I made a program to check the size of a file in Python
I tried to display the altitude value of DTM in a graph
I created a script to check if English is entered in the specified position of the JSON file in Python.
I didn't know the basics of Python
I wanted to know the number of lines in multiple files, so I tried to get it with a command
The file edited with vim was readonly but I want to save it
python I don't know how to get the printer name that I usually use.
[Python] I want to know the variables in the function when an error occurs!
I want to use Python in the environment of pyenv + pipenv on Windows 10
Talking about the features that pandas and I were in charge of in the project
P100-PCIE-16GB was added to the GPU of Google Colab before I knew it
I tried to use Resultoon on Mac + AVT-C875, but I was frustrated on the way.
I made an appdo command to execute a command in the context of the app
AtCoder AGC 041 C --I was addicted to the full search of Domino Quality
I want to set a life cycle in the task definition of ECS
I want to store the result of% time, %% time, etc. in an object (variable)
I made a script to record the active window using win32gui of Python
I tried to visualize the lyrics of GReeeen, which I used to listen to crazy in my youth but no longer listen to it.
I will summarize what I was happy to do to get out of the state where I do not know the letter D of Docker
linux / c> link> Get the execution result of the shell command in the C program> I was taught how to use popen ()
I want to make the LED Lighting of ErgoDox EZ shine, but tell me what the LED is in the first place
The inaccuracy of Tensorflow was due to log (0)
I was able to recurse in Python: lambda
I tried to touch the API of ebay
I tried to correct the keystone of the image
I want to customize the appearance of zabbix
I want to display the progress in Python!
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
I use python but I don't know the class well, so I will do a tutorial
I was soberly addicted to calling awscli from a Python 2.7 script registered in crontab
[Linux] I learned LPIC lv1 in 10 days and tried to understand the mechanism of Linux.
I tried to scrape YouTube, but I can use the API, so don't do it.
The first step of machine learning ~ For those who want to implement with python ~
I tried to extract the text in the image file using Tesseract of the OCR engine
I don't know what HEIC is. But for the time being, let's use PNG!
Here is one of the apps with "artificial intelligence" that I was interested in.
What I did when I was angry to put it in with the enable-shared option
I tried to put HULFT IoT (Agent) in the gateway Rooster of Sun Electronics
[First data science ⑥] I tried to visualize the market price of restaurants in Tokyo
I used Python to find out about the role choices of the 51 "Yachts" in the world.