Fabric

De Linuxmemo.

http://docs.fabfile.org/en/1.4.2/index.html

Sommaire

Installation

apt-get install fabric

ou bien

apt-get install python-pip
pip install fabric

Commande "fab"

fab -H localhost,linuxbox fonction
fab -R role fonction
fab -H localhost -f fabfile.py fonction
fab -H localhost -f fabfile.py -l

Fichier de commande: "fabfile"

Variables d’environnement

   abort_on_prompts
   all_hosts
   always_use_pty
   combine_stderr
   command
   command_prefixes
   connection_attempts
   cwd
   disable_known_hosts
   exclude_hosts
   fabfile
   host_string
   forward_agent
   host
   hosts
   keepalive
   key_filename
   linewise
   local_user
   no_agent
   no_keys
   parallel
   password
   passwords
   path
   pool_size
   port
   real_fabfile
   rcfile
   reject_unknown_hosts
   roledefs
   roles
   shell
   skip_bad_hosts
   ssh_config_path
   sudo_prefix
   sudo_prompt
   timeout
   use_shell
   use_ssh_config
   user
   version
   warn_only

Modèle d’exécution

Exécution en série

Exécution en parallèle

Importer des modules de "fabric.api"

les modules:
abort, cd, env, get, hide, hosts, local, prompt, put, require, roles, run, runs_once, settings, show, sudo, warn
from fabric.api import env run

ou

from fabric.api import *

Définir une lite de machines

Globale:

env.hosts = ['host1', 'host2']

Roles:

from fabric.api import env
env.roledefs = {
    'web': ['www1', 'www2', 'www3'],
    'dns': ['ns1', 'ns2']
}

Via la ligne de commande "fab"

 fab -H host1,host2 mytask
 fab -R roles

Ordre de préférence:

-Per-task, command-line host lists (fab mytask:host=host1) override absolutely everything else.
-Per-task, decorator-specified host lists (@hosts('host1')) override the env variables.
-Globally specified host lists set in the fabfile (env.hosts = ['host1']) can override
such lists set on the command-line, but only if you’re not careful (or want them to.)
-Globally specified host lists set on the command-line (--hosts=host1) will initialize the env variables, but that’s it.

Définir une tache

Outils personnels