Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make - replacement in group names optional #12855

Merged
merged 1 commit into from
Oct 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions contrib/inventory/ec2.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions contrib/inventory/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,12 @@ def read_settings(self):
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',
Expand Down Expand Up @@ -1285,10 +1291,11 @@ def uncammelize(self, key):
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
Expand Down