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
fa32bd34
Commit
fa32bd34
authored
Sep 16, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'michalgasek-ec2-tag-filter' into devel
parents
489574e0
21409d60
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
1 deletions
+35
-1
plugins/inventory/ec2.ini
+20
-0
plugins/inventory/ec2.py
+15
-1
No files found.
plugins/inventory/ec2.ini
View file @
fa32bd34
...
...
@@ -73,3 +73,23 @@ nested_groups = False
# If you want to exclude any hosts that match a certain regular expression
# pattern_exclude = stage-*
# Instance filters can be used to control which instances are retrieved for
# inventory. For the full list of possible filters, please read the EC2 API
# docs: http://docs.aws.amazon.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstances.html#query-DescribeInstances-filters
# Filters are key/value pairs separated by '=', to list multiple filters use
# a list separated by commas. See examples below.
# Retrieve only instances with (key=value) env=stage tag
# instance_filters = tag:env=stage
# Retrieve only instances with role=webservers OR role=dbservers tag
# instance_filters = tag:role=webservers,tag:role=dbservers
# Retrieve only t1.micro instances OR instances with tag env=stage
# instance_filters = instance-type=t1.micro,tag:env=stage
# You can use wildcards in filter values also. Below will list instances which
# tag Name value matches webservers1*
# (ex. webservers15, webservers1a, webservers123 etc)
# instance_filters = tag:Name=webservers1*
plugins/inventory/ec2.py
View file @
fa32bd34
...
...
@@ -123,6 +123,7 @@ from boto import ec2
from
boto
import
rds
from
boto
import
route53
import
ConfigParser
from
collections
import
defaultdict
try
:
import
json
...
...
@@ -272,6 +273,13 @@ class Ec2Inventory(object):
except
ConfigParser
.
NoOptionError
,
e
:
self
.
pattern_exclude
=
None
# Instance filters (see boto and EC2 API docs)
self
.
ec2_instance_filters
=
defaultdict
(
list
)
if
config
.
has_option
(
'ec2'
,
'instance_filters'
):
for
x
in
config
.
get
(
'ec2'
,
'instance_filters'
,
''
)
.
split
(
','
):
filter_key
,
filter_value
=
x
.
split
(
'='
)
self
.
ec2_instance_filters
[
filter_key
]
.
append
(
filter_value
)
def
parse_cli_args
(
self
):
''' Command line argument processing '''
...
...
@@ -316,7 +324,13 @@ class Ec2Inventory(object):
print
(
"region name:
%
s likely not supported, or AWS is down. connection to region failed."
%
region
)
sys
.
exit
(
1
)
reservations
=
conn
.
get_all_instances
()
reservations
=
[]
if
self
.
ec2_instance_filters
:
for
filter_key
,
filter_values
in
self
.
ec2_instance_filters
.
iteritems
():
reservations
.
extend
(
conn
.
get_all_instances
(
filters
=
{
filter_key
:
filter_values
}))
else
:
reservations
=
conn
.
get_all_instances
()
for
reservation
in
reservations
:
for
instance
in
reservation
.
instances
:
self
.
add_instance
(
instance
,
region
)
...
...
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