From d5c309e20de68ea054ebece49ebe8f91755ea9f4 Mon Sep 17 00:00:00 2001 From: Will Thames Date: Fri, 7 Feb 2014 22:30:16 +1000 Subject: [PATCH] Pick up default EC2 region from boto.config This doesn't account for boto configs where e.g. RDS has one default region and EC2 another - all will default to `ec2_region_name`. However, this is just handy to allow an easy site wide default region if existing configuration already relies on it. Modules can be improved to mention this in the documentation and turn off required=True where needed. But it works with `ec2` and `ec2_vol` without change. --- lib/ansible/module_utils/ec2.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/ansible/module_utils/ec2.py b/lib/ansible/module_utils/ec2.py index bbcd30be21..a0bdaf2b8f 100644 --- a/lib/ansible/module_utils/ec2.py +++ b/lib/ansible/module_utils/ec2.py @@ -53,6 +53,9 @@ def get_ec2_creds(module): region = os.environ['EC2_REGION'] elif 'AWS_REGION' in os.environ: region = os.environ['AWS_REGION'] + else: + # boto.config.get returns None if config not found + region = boto.config.get('Boto', 'ec2_region_name') return ec2_url, ec2_access_key, ec2_secret_key, region