pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

files.line grep inserts wrong regex

Open JustScreaMy opened this issue 2 years ago • 2 comments

Describe the bug

Using files.line to replace single line produces incorrect fact, so the line is never replaced and therefore automatically inserted at the end of the file

To Reproduce

  • Operation code & usage
from pyinfra.operations import files

files.line(
        name="Disable password login",
        path="/etc/ssh/sshd_config",
        line="PasswordAuthentication .+",
        replace="PasswordAuthentication no"
)

Expected behavior

This code should match line containing PasswordAuthentication yes and replace in with PasswordAuthentication no

Meta

  • Consider including output with -vv and --debug. This is grep generated by the files.line operation sh -c 'grep -e '"'"'^.*.+PasswordAuthentication.+.*$'"'"' /etc/ssh/sshd_config

JustScreaMy avatar Oct 04 '23 19:10 JustScreaMy

Yep this looks wrong, thanks for reporting I'll fix this up!

Fizzadar avatar Nov 25 '23 19:11 Fizzadar