Comments (6)
As far as I can tell, you assume env
is persistent between tasks? This is not the case. You need to save state somewhere else.
add_instance_to_env
is used by awsfabrictasks.main.get_hosts_supporting_aws
to register autogenerated Ec2InstanceWrapper
instances based on command line options (-E
, --ec2tags
or --ec2ids
).
One solution is to use Ec2 tags to save state, and use --ec2tags
to perform actions on all instances with the same tag. We also provide a few utilities and helpers for tags.
To sum this up, you will most likely want to do something like this:
@tasks
def setup():
a = Ec2LaunchInstance(extra_tags={'Name': 'nginxserver', 'Environment': 'my_super_webapp'})
b = Ec2LaunchInstance(extra_tags={'Name': 'djangoserver', 'Environment': 'my_super_webapp'})
Ec2LaunchInstance.confirm_many([a, b])
Ec2LaunchInstance.run_many_instances([a, b])
# Note: that we can start doing stuff with ``a`` and ``b`` that does not
# require the instances to be running, such as setting tags.
Ec2LaunchInstance.wait_for_running_state_many([a, b])
@task
def dosomething():
"""
Typically called with ``awsfab --ec2tags my_super_webapp dosomething``.
"""
run('uname -a')
@task
@ec2instance(tags={'Environment': 'my_super_webapp'})
def dosomething_for_my_super_webapp():
"""
Called with ``awsfab dosomething_for_my_super_webapp``.
"""
run('whoami')
You should also take a look at #11.
from awsfabrictasks.
Ah okay, thank you very much for the explanation! So this is not a bug, I just had a different mental model of what was going on ... Doing this via tags seems pretty neat.
Just to make sure I got this right: Using the example fabfile you provided (thanks!), calling awsfab setup dosomething_for_my_super_webapp
should launch two instances named nginxserver
and djangoserver
, and then execute whoami
on both?
I copied the code from your comment into a fabfile.py
, added the required imports, fixed a typo (@tasks
-> @task
in the first line) and ran awsfab setup dosomething_for_my_super_webapp
. The setup
part launches the instances just fine (they show up as "running" on the EC2 Management Console), but then dosomething_for_my_super_webapp
prints
No hosts found. Please specify (single) host string for connection:
-- is that the expected behaviour? My understanding from your explanation was that at this point, the ec2instances
decorator should feed the two instances created in setup
to dosomething_for_my_super_webapp
because they were both tagged with the my_super_webapp
environment.
from awsfabrictasks.
As far as I remember it should work like https://fabric.readthedocs.org/en/1.3.0/usage/parallel.html, but I have not used it for a couple of months and I created the code over a year ago so I may be remembering it wrong. If the tag matching does not work like specifying multiple hosts, we should provide another way of doing what you want to do using tags.
from awsfabrictasks.
Sorry -- could you explain what you mean by "it should work like @parallel
"?
from awsfabrictasks.
Sorry that was not explained clearly! It should not work like @parallel
, but it should work like specifying multiple hosts. I.E.: awsfab --ec2tags mytag
should work like specifying fab -H a,b
as long as a
and b
is tagged with mytag
. I guess this is not the case, and I or someone willing to make a patch will have to look into fixing it, or creating an alternative command line option for matching multiple hosts with a single tag.
from awsfabrictasks.
Cheers! By sneaking in a couple of print
statements, I found a possible explanation for this behaviour: It seems like the @ec2instance
decorator is called when awsfab
starts up, as opposed to when the task is actually executed.
This means that in the particular case of the example code above, in decorator.py, line 34, instancewrappers
is assigned to the list of instance wrappers for instances with the tag 'Environment':'my_super_webapp'
that exist when the script is called. When the task dosomething_for_my_super_webapp
is finally executed, it is run on this list of instances, which does not include the ones launched in the setup
task.
from awsfabrictasks.
Related Issues (14)
- Is there a way to specify an AWS IAM role when using awsfab ec2_launch_instance? HOT 6
- VPC instances HOT 4
- Could not find the env.awsfab_settings_module HOT 2
- @ec2instance: login issue
- Run tasks on multiple hosts HOT 4
- Doesn't work with Fabric 1.9.0+ HOT 1
- Getting the current Instance
- Requires ec2 with public DNS?
- lunching t2.micro instance is failing
- Rename ec2.api.ec2_rsync
- Implement instancewrapper.instance_settings()
- Recommended setup for multiple AWS accounts? HOT 1
- ec2_list_instances broken with boto 2.6.0 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from awsfabrictasks.