Skip to content

files.block doesn't correctly prepend a block when it should #1416

@morrison12

Description

@morrison12

Describe the bug

When before and after are both True and line is specified and is not found, files.block should prepend contents but instead appends them.

To Reproduce

echo bar > test.txt
pyinfra @local files.block path="test.txt" content="block contents" present=True after=True before=True
cat test.txt
bar
# BEGIN PYINFRA BLOCK
block contents
# END PYINFRA BLOCK

Expected behavior

test.txt should contain

# BEGIN PYINFRA BLOCK
block contents
# END PYINFRA BLOCK
bar

Meta

  • Include output of pyinfra --support.
    System: Darwin
      Platform: macOS-14.7.7-arm64-arm-64bit
      Release: 23.6.0
      Machine: arm64
    pyinfra: v3.4.1
  Executable: /Users/.../.virtualenvs/pyinfra-dev/bin/pyinfra
      Python: 3.12.7 (CPython, Clang 16.0.0 (clang-1600.0.26.4))
  • How was pyinfra installed (source/pip)?
pip install -e '.[dev]'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions