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 () 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
When 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