Differences between revisions 6 and 7
Revision 6 as of 2018-07-25 09:03:41
Size: 1736
Editor: risca
Comment:
Revision 7 as of 2018-07-25 09:05:15
Size: 1770
Editor: risca
Comment:
Deletions are marked like this. Additions are marked like this.
Line 34: Line 34:
{{{ {{{#!highlight pycon
Line 48: Line 48:
{{{ {{{#!highlight pycon

Warning: from fabric 2 to version 1 everything changes!

Since 2.0 all commands are execute through invoke while fab manage only the Connection.

Quick reference

Runner

(from invoke http://docs.pyinvoke.org/en/latest/api/runners.html)

Main parameters for run:

  • command
  • shell
  • warn
  • hide: [out|err|both|None]
  • pty
  • echo: show what will be execute
  • env: inject variables
  • replace_env: it will be the only environment
  • watchers: automatic replay to stdout!
  • echo_stdin
  • respond: write in response of watcher

local: same as run but execute on the local host

Exit codes attributes:

  • ok|failed
  • exited
  • return_code
  • stdout
  • connection.host

Usage by examples

Autoresponder

   1 >>> from invoke import Responder
   2 >>> from fabric import Connection
   3 >>> c = Connection('host')
   4 >>> sudopass = Responder(
   5 ...     pattern=r'\[sudo\] password:',
   6 ...     response='mypassword\n',
   7 ... )
   8 >>> c.run('sudo whoami', pty=True, watchers=[sudopass])
   9 [sudo] password:
  10 root
  11 <Result cmd='sudo whoami' exited=0>
  12 

Sudo

   1 >>> import getpass
   2 >>> from fabric import Connection, Config
   3 >>> sudo_pass = getpass.getpass("What's your sudo password?")
   4 What's your sudo password?
   5 >>> config = Config(overrides={'sudo': {'password': sudo_pass}})
   6 >>> c = Connection('db1', config=config)
   7 >>> c.sudo('whoami', hide='stderr')
   8 root
   9 <Result cmd="...whoami" exited=0>
  10 >>> c.sudo('useradd mydbuser')
  11 <Result cmd="...useradd mydbuser" exited=0>
  12 >>> c.run('id -u mydbuser')
  13 1001
  14 <Result cmd='id -u mydbuser' exited=0>
  15 

Documentation

MyWiki: fabric (last edited 2018-07-25 09:12:28 by risca)