Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
e7890e66
Commit
e7890e66
authored
Sep 24, 2014
by
Jameel Al-Aziz
Committed by
Abhijit Menon-Sen
Sep 28, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine ansible/ansible#5987 and ansible/ansible#8582
Fixes merge conflicts and standardizes option naming
parent
8c11ea56
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
25 deletions
+30
-25
contrib/inventory/ec2.py
+30
-25
No files found.
contrib/inventory/ec2.py
View file @
e7890e66
...
@@ -22,11 +22,11 @@ you need to define:
...
@@ -22,11 +22,11 @@ you need to define:
export EC2_URL=http://hostname_of_your_cc:port/services/Eucalyptus
export EC2_URL=http://hostname_of_your_cc:port/services/Eucalyptus
If you're using boto profiles (requires boto>=2.24.0) you can choose a profile
If you're using boto profiles (requires boto>=2.24.0) you can choose a profile
using the --
profile command line argument (e.g. ec2.py -
-profile prod) or using
using the --
boto-profile command line argument (e.g. ec2.py --boto
-profile prod) or using
the
EC2
_PROFILE variable:
the
AWS
_PROFILE variable:
EC2
_PROFILE=prod ansible-playbook -i ec2.py myplaybook.yml
AWS
_PROFILE=prod ansible-playbook -i ec2.py myplaybook.yml
For more details, see: http://docs.pythonboto.org/en/latest/boto_config_tut.html
For more details, see: http://docs.pythonboto.org/en/latest/boto_config_tut.html
...
@@ -154,20 +154,19 @@ class Ec2Inventory(object):
...
@@ -154,20 +154,19 @@ class Ec2Inventory(object):
# Index of hostname (address) to instance ID
# Index of hostname (address) to instance ID
self
.
index
=
{}
self
.
index
=
{}
# Parse CLI arguments and read settings
# Boto profile to use (if any)
self
.
boto_profile
=
None
# Read settings and parse CLI arguments
self
.
parse_cli_args
()
self
.
parse_cli_args
()
self
.
read_settings
()
self
.
read_settings
()
# boto profile to use (if any)
# Make sure that profile_name is not passed at all if not set
# Make sure that profile_name is not passed at all if not set
# as pre 2.24 boto will fall over otherwise
# as pre 2.24 boto will fall over otherwise
if
self
.
args
.
profile
:
if
self
.
boto_
profile
:
if
not
hasattr
(
boto
.
ec2
.
EC2Connection
,
'profile_name'
):
if
not
hasattr
(
boto
.
ec2
.
EC2Connection
,
'profile_name'
):
sys
.
stderr
.
write
(
"boto version must be >= 2.24 to use profile
\n
"
)
sys
.
stderr
.
write
(
"boto version must be >= 2.24 to use profile
\n
"
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
self
.
profile
=
dict
(
profile_name
=
self
.
args
.
profile
)
else
:
self
.
profile
=
dict
()
# Cache
# Cache
if
self
.
args
.
refresh_cache
:
if
self
.
args
.
refresh_cache
:
...
@@ -307,10 +306,15 @@ class Ec2Inventory(object):
...
@@ -307,10 +306,15 @@ class Ec2Inventory(object):
else
:
else
:
self
.
all_elasticache_nodes
=
False
self
.
all_elasticache_nodes
=
False
# boto configuration profile (prefer CLI argument)
self
.
boto_profile
=
self
.
args
.
boto_profile
if
config
.
has_option
(
'ec2'
,
'boto_profile'
)
and
not
self
.
boto_profile
:
self
.
boto_profile
=
config
.
get
(
'ec2'
,
'boto_profile'
)
# Cache related
# Cache related
cache_dir
=
os
.
path
.
expanduser
(
config
.
get
(
'ec2'
,
'cache_path'
))
cache_dir
=
os
.
path
.
expanduser
(
config
.
get
(
'ec2'
,
'cache_path'
))
if
self
.
args
.
profile
:
if
self
.
boto_
profile
:
cache_dir
=
os
.
path
.
join
(
cache_dir
,
'profile_'
+
self
.
args
.
profile
)
cache_dir
=
os
.
path
.
join
(
cache_dir
,
'profile_'
+
self
.
boto_
profile
)
if
not
os
.
path
.
exists
(
cache_dir
):
if
not
os
.
path
.
exists
(
cache_dir
):
os
.
makedirs
(
cache_dir
)
os
.
makedirs
(
cache_dir
)
...
@@ -318,11 +322,6 @@ class Ec2Inventory(object):
...
@@ -318,11 +322,6 @@ class Ec2Inventory(object):
self
.
cache_path_index
=
cache_dir
+
"/ansible-ec2.index"
self
.
cache_path_index
=
cache_dir
+
"/ansible-ec2.index"
self
.
cache_max_age
=
config
.
getint
(
'ec2'
,
'cache_max_age'
)
self
.
cache_max_age
=
config
.
getint
(
'ec2'
,
'cache_max_age'
)
# boto configuration profile
self
.
boto_profile
=
None
if
config
.
has_option
(
'ec2'
,
'boto_profile'
):
self
.
boto_profile
=
config
.
get
(
'ec2'
,
'boto_profile'
)
# Configure nested groups instead of flat namespace.
# Configure nested groups instead of flat namespace.
if
config
.
has_option
(
'ec2'
,
'nested_groups'
):
if
config
.
has_option
(
'ec2'
,
'nested_groups'
):
self
.
nested_groups
=
config
.
getboolean
(
'ec2'
,
'nested_groups'
)
self
.
nested_groups
=
config
.
getboolean
(
'ec2'
,
'nested_groups'
)
...
@@ -387,6 +386,7 @@ class Ec2Inventory(object):
...
@@ -387,6 +386,7 @@ class Ec2Inventory(object):
continue
continue
self
.
ec2_instance_filters
[
filter_key
]
.
append
(
filter_value
)
self
.
ec2_instance_filters
[
filter_key
]
.
append
(
filter_value
)
def
parse_cli_args
(
self
):
def
parse_cli_args
(
self
):
''' Command line argument processing '''
''' Command line argument processing '''
...
@@ -397,7 +397,7 @@ class Ec2Inventory(object):
...
@@ -397,7 +397,7 @@ class Ec2Inventory(object):
help
=
'Get all the variables about a specific instance'
)
help
=
'Get all the variables about a specific instance'
)
parser
.
add_argument
(
'--refresh-cache'
,
action
=
'store_true'
,
default
=
False
,
parser
.
add_argument
(
'--refresh-cache'
,
action
=
'store_true'
,
default
=
False
,
help
=
'Force refresh of cache by making API requests to EC2 (default: False - use cache files)'
)
help
=
'Force refresh of cache by making API requests to EC2 (default: False - use cache files)'
)
parser
.
add_argument
(
'--
profile'
,
action
=
'store'
,
default
=
os
.
environ
.
get
(
'EC2_PROFILE'
)
,
parser
.
add_argument
(
'--
boto-profile'
,
action
=
'store'
,
help
=
'Use boto profile for connections to EC2'
)
help
=
'Use boto profile for connections to EC2'
)
self
.
args
=
parser
.
parse_args
()
self
.
args
=
parser
.
parse_args
()
...
@@ -431,18 +431,23 @@ class Ec2Inventory(object):
...
@@ -431,18 +431,23 @@ class Ec2Inventory(object):
self
.
fail_with_error
(
"region name:
%
s likely not supported, or AWS is down. connection to region failed."
%
region
)
self
.
fail_with_error
(
"region name:
%
s likely not supported, or AWS is down. connection to region failed."
%
region
)
return
conn
return
conn
def
boto_fix_security_token_in_profile
(
self
,
conn
):
def
boto_fix_security_token_in_profile
(
self
,
conn
ect_args
):
''' monkey patch for boto issue boto/boto#2100 '''
''' monkey patch for boto issue boto/boto#2100 '''
profile
=
'profile '
+
self
.
profile
.
get
(
'profile_name'
)
profile
=
'profile '
+
self
.
boto_profile
if
boto
.
config
.
has_option
(
profile
,
'aws_security_token'
):
if
boto
.
config
.
has_option
(
profile
,
'aws_security_token'
):
conn
.
provider
.
set_security_token
(
boto
.
config
.
get
(
profile
,
'aws_security_token'
)
)
conn
ect_args
[
'secuirty_token'
]
=
boto
.
config
.
get
(
profile
,
'aws_security_token'
)
return
conn
return
conn
ect_args
def
connect_to_aws
(
self
,
module
,
region
):
def
connect_to_aws
(
self
,
module
,
region
):
conn
=
module
.
connect_to_region
(
region
,
**
self
.
profile
)
connect_args
=
{}
if
'profile_name'
in
self
.
profile
:
conn
=
self
.
boto_fix_security_token_in_profile
(
conn
)
# only pass the profile name if it's set (as it is not supported by older boto versions)
if
self
.
boto_profile
:
connect_args
[
'profile_name'
]
=
self
.
boto_profile
self
.
boto_fix_security_token_in_profile
(
connect_args
)
conn
=
module
.
connect_to_region
(
region
,
**
connect_args
)
return
conn
return
conn
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment