Simple question. I'm trying to match "UseDns", "usedns" and other variations.
- name: Disable DNS checking on login (huge speedup)
sudo: true
lineinfile:
dest: "/etc/ssh/sshd_config"
regexp: "^[# \t]*[Uu][Ss][Ee][Dd][Nn][Ss] "
# how does one specify case insensitive regexp in lineinfile?
line: "UseDNS no"
state: "present"
create: true
insertafter: EOF
notify:
- sshd restart
Ansible uses Python re module. You can use inline modifiers, such as (?ism)
in your pattern. Use the i for case-insensitive matching:
regexp: "(?i)^[# \t]*usedns "
Inline modifiers apply to the part of the regular experssion to the right of the modifier, and can be disabled with a -
e.g. (?-i)
. This can be applied to implement case-insensitivity to only a part of a regular expression.
For example, the regex (?i)use(?-i)DNS
should match useDNS
and UseDNS
, but not useDns
or USEdns
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With