Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 14215

Ansible-lint Custom Rule Matching with Regex

$
0
0

I want to use Ansible-lint to check to see if subnets are formatted correctly in my yaml files.

right: 10.10.10.0/32

Wrong: 10.10.10.0 /32

I created a custom rule:

     from ansiblelint import AnsibleLintRule     import re     class CheckCustomPattern(AnsibleLintRule):         id = 'CUSTOM005'         shortdesc = 'Check if pattern "\\s\/[1-3][0-9]" is found'         description = 'This rule checks if the pattern "\\s\/[1-3][0-9]" is found in any file.'         severity = 'HIGH'         tags = ['files']         def match(self, file, text):             with open(file['path'], 'r') as file_content:                 content = file_content.read()                 if re.search(r'\s\/[1-3][0-9]', content):                     return True             return False

I have checked the Regex against a tester and it is correct.

When I run it, tt is matching on all IP addresses, even ones that are correct. It is even matching on non-IP addresses, like random string like [ TCP UDP ICMP ]. I have checked the regex syntax in a tester and it is correct.

Not sure what I am missing.


Viewing all articles
Browse latest Browse all 14215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>