Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm guessing here a little, but I'm assuming you've got into trouble because you're trying to solve two problems at once. </p> <p>The first issue relates to the issue of multiple hosts. Fabric includes the concepts of <a href="http://docs.fabfile.org/en/latest/usage/execution.html#roles" rel="nofollow">roles</a>, which are just groups of machines that you can issue commands to in one go. The information in the <code>find_instances</code> function could be used to populate this data.</p> <pre><code>from fabric import * from something import find_instances env.roledefs = { 'eu-west-1' : find_instances('eu-west-1'), 'eu-west-2' : find_instances('eu-west-2'), } @task def restart_apache2(): run('/etc/init.d/apache2 restart') </code></pre> <p>The second issue is that you have different keys for different groups of servers. One way to resolve this problem is to use an SSH config file to prevent you from having to mix the details of the keys / users accounts with your fabric code. You can either add an entry per instance into your <code>~/.ssh/config</code>, or you can use <a href="http://docs.fabfile.org/en/latest/usage/execution.html#ssh-config" rel="nofollow">local SSH config</a> (<code>env.use_ssh_config</code> and <code>env.ssh_config_path</code>)</p> <pre><code>Host instance00 User admin IdentityFile keys/key_instance00_prod.pem Host instance01 User admin IdentityFile keys/key_instance01_prod.pem # ... </code></pre> <p>On the command line, you should then be able to issue the commands like:</p> <pre><code>fab restart_apache2 -R eu-west-1 </code></pre> <p>Or, you can still do single hosts:</p> <pre><code>fab restart_apache2 -H apache2 </code></pre> <p>In your script, these two are equivalent to the <a href="http://docs.fabfile.org/en/latest/usage/execution.html#intelligently-executing-tasks-with-execute" rel="nofollow">execute</a> function:</p> <pre><code>from fabric.api import execute from fabfile import restart_apache2 execute(restart_apache2, roles = ['eu-west-1']) execute(restart_apache2, hosts = ['apache2']) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload