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
7c2cc15c
Commit
7c2cc15c
authored
Aug 08, 2014
by
Michael Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding include_pattern and exclude_pattern options to ec2.py
parent
d4cedfc7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
plugins/inventory/ec2.ini
+6
-0
plugins/inventory/ec2.py
+24
-0
No files found.
plugins/inventory/ec2.ini
View file @
7c2cc15c
...
...
@@ -67,3 +67,9 @@ cache_max_age = 300
# Organize groups into a nested/hierarchy instead of a flat namespace.
nested_groups
=
False
# If you only want to include hosts that match a certain regular expression
# pattern_include = stage-*
# If you want to exclude any hosts that match a certain regular expression
# pattern_exclude = stage-*
plugins/inventory/ec2.py
View file @
7c2cc15c
...
...
@@ -252,6 +252,22 @@ class Ec2Inventory(object):
else
:
self
.
nested_groups
=
False
# Do we need to just include hosts that match a pattern?
try
:
pattern_include
=
config
.
get
(
'ec2'
,
'pattern_include'
)
if
pattern_include
and
len
(
pattern_include
)
>
0
:
self
.
pattern_include
=
re
.
compile
(
pattern_include
)
except
ConfigParser
.
NoOptionError
,
e
:
self
.
pattern_include
=
None
# Do we need to exclude hosts that match a pattern?
try
:
pattern_exclude
=
config
.
get
(
'ec2'
,
'pattern_exclude'
);
if
pattern_exclude
and
len
(
pattern_exclude
)
>
0
:
self
.
pattern_exclude
=
re
.
compile
(
pattern_exclude
)
except
ConfigParser
.
NoOptionError
,
e
:
self
.
pattern_exclude
=
''
def
parse_cli_args
(
self
):
''' Command line argument processing '''
...
...
@@ -359,6 +375,14 @@ class Ec2Inventory(object):
# Skip instances we cannot address (e.g. private VPC subnet)
return
# if we only want to include hosts that match a pattern, skip those that don't
if
self
.
pattern_include
and
not
self
.
pattern_include
.
match
(
dest
):
return
# if we need to exclude hosts that match a pattern, skip those
if
self
.
pattern_exclude
and
self
.
pattern_exclude
.
match
(
dest
):
return
# Add to index
self
.
index
[
dest
]
=
[
region
,
instance
.
id
]
...
...
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