summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <bcoca@ansible.com>2015-10-26 13:28:35 -0400
committerBrian Coca <bcoca@ansible.com>2015-10-26 13:28:35 -0400
commit2b8633cec0b105a50aec384c28cadb1a7e00c75b (patch)
treece1e3a1b572442c9fd0da02367832b4b5836733b
parent0fd1d1691bcaf4e2fbafcb725f19d3af0c62bec6 (diff)
parent07d584c0a7ffb5927d62ac9ba59e4f6ccea17fb7 (diff)
downloadansible-2b8633cec0b105a50aec384c28cadb1a7e00c75b.tar.gz
Merge pull request #12855 from bcoca/ec2_inv_dash_group
make - replacement in group names optional
-rw-r--r--contrib/inventory/ec2.ini3
-rwxr-xr-xcontrib/inventory/ec2.py15
2 files changed, 14 insertions, 4 deletions
diff --git a/contrib/inventory/ec2.ini b/contrib/inventory/ec2.ini
index 93be4c8acb..f3b75570f6 100644
--- a/contrib/inventory/ec2.ini
+++ b/contrib/inventory/ec2.ini
@@ -94,6 +94,9 @@ cache_max_age = 300
# Organize groups into a nested/hierarchy instead of a flat namespace.
nested_groups = False
+# Replace - tags when creating groups to avoid issues with ansible
+replace_dash_in_groups = True
+
# The EC2 inventory output can become very large. To manage its size,
# configure which groups should be created.
group_by_instance_id = True
diff --git a/contrib/inventory/ec2.py b/contrib/inventory/ec2.py
index fd1cebe202..822220b072 100755
--- a/contrib/inventory/ec2.py
+++ b/contrib/inventory/ec2.py
@@ -327,6 +327,12 @@ class Ec2Inventory(object):
else:
self.nested_groups = False
+ # Replace dash or not in group names
+ if config.has_option('ec2', 'replace_dash_in_groups'):
+ self.replace_dash_in_groups = config.getboolean('ec2', 'replace_dash_in_groups')
+ else:
+ self.replace_dash_in_groups = True
+
# Configure which groups should be created.
group_by_options = [
'group_by_instance_id',
@@ -1285,10 +1291,11 @@ class Ec2Inventory(object):
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', temp).lower()
def to_safe(self, word):
- ''' Converts 'bad' characters in a string to underscores so they can be
- used as Ansible groups '''
-
- return re.sub("[^A-Za-z0-9\_]", "_", word)
+ ''' Converts 'bad' characters in a string to underscores so they can be used as Ansible groups '''
+ regex = "[^A-Za-z0-9\_"
+ if self.replace_dash_in_groups:
+ regex += "\-"
+ return re.sub(regex + "]", "_", word)
def json_format_dict(self, data, pretty=False):
''' Converts a dict to a JSON object and dumps it as a formatted