| | 1 | [[PageOutline]] |
| | 2 | = Fabric = |
| | 3 | |
| | 4 | [http://fabfile.org fabric] is a python framework for executing commands either locally or on a series of remote hosts. |
| | 5 | |
| | 6 | Our [wiki:puppet puppet repo] contains a fabric directory with a fabfile.py the defines commands to help with the management of our servers. |
| | 7 | |
| | 8 | == Why do we need fabric if we have puppet? == |
| | 9 | |
| | 10 | Puppet allows us to easily ensure that a set of commands and files are executed and copied to our servers (and will execute/copy the commands/files over and over again if necessary). |
| | 11 | |
| | 12 | fabric allows us to execute/copy a command/file to one or more servers once and witness the output. Also, fabric allows us to perform operations locally, like list available servers or automate setting up a git remote for each server's puppet repository. |
| | 13 | |
| | 14 | == How do I install fabric? == |
| | 15 | |
| | 16 | {{{ |
| | 17 | apt-get install fabric |
| | 18 | }}} |
| | 19 | |
| | 20 | I've written our fabfile.py using fabric 0.9.1. |
| | 21 | |
| | 22 | == How do I use our fabric commands? == |
| | 23 | |
| | 24 | First, cd into the fabric directory. All fabric commands must be executed from the fabric directory. |
| | 25 | |
| | 26 | Next, run the fab command followed by one or more sub-commands. |
| | 27 | |
| | 28 | For example: |
| | 29 | |
| | 30 | {{{ |
| | 31 | fab listServers |
| | 32 | }}} |
| | 33 | |
| | 34 | Will generate a list of servers located in our manifests/nodes/production directory. |
| | 35 | |
| | 36 | You can limit the list by adding a colon separted argument to the command, by either specifying a specific server: |
| | 37 | |
| | 38 | {{{ |
| | 39 | 0 jamie@chicken:fabric$ fab listServers:mandela |
| | 40 | mandela |
| | 41 | |
| | 42 | Done. |
| | 43 | 0 jamie@chicken:fabric$ |
| | 44 | }}} |
| | 45 | |
| | 46 | Or, by specifying a phrase to grep all server manifests for: |
| | 47 | |
| | 48 | {{{ |
| | 49 | 0 jamie@chicken:fabric$ fab listServers:mosh |
| | 50 | albizu |
| | 51 | chavez |
| | 52 | daza |
| | 53 | debs |
| | 54 | didier |
| | 55 | eagle |
| | 56 | ella |
| | 57 | jones |
| | 58 | julia |
| | 59 | june |
| | 60 | lucius |
| | 61 | lucy |
| | 62 | lumumba |
| | 63 | malcolm |
| | 64 | mandela |
| | 65 | menchu |
| | 66 | proudhon |
| | 67 | rodolpho |
| | 68 | roe |
| | 69 | sojourner |
| | 70 | viewsic |
| | 71 | |
| | 72 | Done. |
| | 73 | 0 jamie@chicken:fabric$ |
| | 74 | }}} |
| | 75 | |
| | 76 | listServers is a local command, meaning it is executed on your computer. |
| | 77 | |
| | 78 | In addition, there are several available remote commands, which will execute on remote servers. When running a remote command, the hosts you want to execute on much be specified with the h command, using the same syntax as listServers. For example, the true command is a test command that simply executes /usr/bin/true on the remote server: |
| | 79 | |
| | 80 | {{{ |
| | 81 | 0 jamie@chicken:fabric$ fab h:mandela true |
| | 82 | [root@mandela.mayfirst.org] run: true |
| | 83 | |
| | 84 | Done. |
| | 85 | Disconnecting from root@mandela.mayfirst.org... done. |
| | 86 | 0 jamie@chicken:fabric$ |
| | 87 | }}} |
| | 88 | |
| | 89 | == What other commands are available? == |
| | 90 | |
| | 91 | Run: |
| | 92 | |
| | 93 | {{{ |
| | 94 | fab -l |
| | 95 | }}} |
| | 96 | |
| | 97 | To see a list of all available commands. |
| | 98 | |
| | 99 | == How can I add new commands? == |
| | 100 | |
| | 101 | Simply edit the fabfile.py and commit and push your changes. |