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

ec2.py dynamic inventory applies the replace_dash_in_groups opposite of what is expected #13122

Closed
twiest opened this issue Nov 10, 2015 · 0 comments
Labels
bug This issue/PR relates to a bug.

Comments

@twiest
Copy link

twiest commented Nov 10, 2015

Issue Type:
  • Bug Report
Ansible Version:

ec2.py inventory from devel branch on github, git commit faeccb4.

Ansible Configuration:

Nothing, I'm running ec2.py directly.

Environment:

Fedora 21 x86_64, but probably N/A.

Summary:

The ec2.py inventory's to_safe method has the logic for replace_dash_in_groups opposite of what is expected.

Currently it's this:

    def to_safe(self, 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)

I think it should be this (notice the "if not"):

    def to_safe(self, word):
        ''' Converts 'bad' characters in a string to underscores so they can be used as Ansible groups '''
        regex = "[^A-Za-z0-9\_"
        if not self.replace_dash_in_groups:
            regex += "\-"
        return re.sub(regex + "]", "_", word)

If this change is added, to maintain backwards compatibility, I think you need to default it to False like this:

        # 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 = False
Steps To Reproduce:
  • Add this to ec2.ini: replace_dash_in_groups = yes
  • Run ec2.py directly: ec2.py --refresh-cache
  • Notice in the output that the group name dashes have not been replaced as expected.
  • Change ec2.ini to this: replace_dash_in_groups = no
  • Run ec2.py directly: ec2.py --refresh-cache
  • Notice in the output that the group name dashes have unexpectedly been replaced.
Expected Results:

When I say "yes" to "replace_dash_in_groups" it should replace the dashes.

When I say "no," it should not replace the dashes.

Actual Results:

It applies the setting opposite of what is expected.

@bcoca bcoca closed this as completed in b2a9111 Nov 10, 2015
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

No branches or pull requests

3 participants