Regular Expressions 101

Community Patterns

Ansible Host Var checking

2

Regular Expression
Python

r"
^([a-zA-Z0-9_\-]+(,?[a-zA-Z0-9_\-]+))*$
"
mg

Description

We had an issue where the "hosts=some_var" value could cause mass deployments if the wrong value was passed through. Specifically a comma with nothing surrounding it (i.e. "hosts=,"). This regex will allow us to fail when certain characters are present.

Submitted by anonymous - 7 years ago