Herramientas de usuario

Herramientas del sitio


otros:fabric

¡Esta es una revisión vieja del documento!


Tabla de Contenidos

Fabric

Fabric es una herramienta para lanzar comandos de consola en local o vía ssh. Facilita la creación de scripts de administración.

Básico

Para instalar haremos:

$ pip install fabric

La instalación añade un script llamado fab, éste interpreta y ejecuta los fabfile's. Un ejemplo de fabfile.py:

from fabric.api import run
def host_type():
    run('uname -sra')

Para lanzarlo haremos:

$ fab -H 127.0.0.1,192.168.1.20 host_type
[127.0.0.1] Executing task 'host_type'
[127.0.0.1] run: uname -sra
[127.0.0.1] Login password for 'alfred': 
[127.0.0.1] out: Linux alfreds-laptop 3.0.0-13-generic #22-Ubuntu SMP Wed Nov 2 13:25:36 UTC 2011 i686 i686 i386 GNU/Linux
[127.0.0.1] out: 
[192.168.1.20] Executing task 'host_type'
[192.168.1.20] run: uname -sra
[192.168.1.20] out: Linux alfredspc 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010 i686 GNU/Linux
[192.168.1.20] out: 
Done.
Disconnecting from 127.0.0.1... done.
Disconnecting from 192.168.1.20... done.

Funciones

En la API de fabric (fabric.api) encontramos las siguientes funciones:

  • local: execute a local command
  • run: execute a remote command on all specific hosts, user-level permissions
  • sudo: sudo a command on the remote server
  • put: copy over a local file to a remote destination
  • get: download a file from the remote server
  • prompt: prompt user with text and return the input (like raw_input))
  • reboot: reboot the remote system, disconnect, and wait for wait seconds
otros/fabric.1377448710.txt.gz · Última modificación: 2020/05/09 09:25 (editor externo)