pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.85k stars 374 forks source link

Cronjobs/line replacements ending `2>&1` break #961

Closed Fizzadar closed 6 months ago

Fizzadar commented 1 year ago

Describe the bug

A clear and concise description of what the bug is.

When ending a line replacement with 2>&1 the line is not replaced properly and a broken line, growing each deploy, is instead. Repro below.

To Reproduce

Steps to reproduce the behavior, please include where possible:

files.line(
    name="Ensure step cron",
    path="/usr/lib/cron/tabs/root",
    line="/usr/local/bin/step",
    replace="0 * * * * /usr/local/bin/step ca renew --root ca.crt --ca-url https://ca.com mtls.crt mtls.key >> /tmp/step-renew.log 2&>1",
)

Expected behavior

A clear and concise description of what you expected to happen.

Replace the line properly

Fizzadar commented 6 months ago

Fixed in https://github.com/pyinfra-dev/pyinfra/commit/d1092ad63b5c1659a9cfc1e224c9b6ce3a311ae7