Skip to main content

blockinfile

blockinfile is a tool for editing automatically a text block surrounded by marker lines. It's an automated port of ansible's blockinfile module.

Basically, it can overwrite a part of a file that's well delimited so it doesn't overwrite the whole file.

Usage

blockinfile --path FILE_TO_PATCH --block CONTENT_TO_INSERT [--marker MARKER_TEMPLATE] [--marker-begin START_STRING] [--marker-end END_STRING] [MORE_OPTIONS]

Options are the same as in Ansible documentation.

Sample

If myfile.conf initially contains:

sample line
other line

Then running:

blockinfile --path myfile.conf --marker "# {mark} MY BLOCK" --block 'this line will be entered
this one too'

Then myfile.conf will be updated:

sample line
other line
# BEGIN MY BLOCK
this line will be entered
this one too
# END MY BLOCK

Then running:

blockinfile --path myfile.conf --marker "# {mark} MY BLOCK" --block 'updating the section'

Would produce:

sample line
other line
# BEGIN MY BLOCK
updating the section
# END MY BLOCK

"Automated" port

This project includes the source of Ansible's blockinfile module, slightly modified so it can work without having to use or even install Ansible. The modifications have been automated so it should be possible to easily port newer Ansible versions.

See builder/build.sh.

Install

From PyPI:

pipx install blockinfile

License

Since blockinfile is a port of (part of) Ansible's source, it's licensed under GPLv3+ just like Ansible.

Metadata

Release files for blockinfile 2.17.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for blockinfile 2.17.1
File Size Uploaded Provenance Actions
blockinfile-2.17.1.tar.gz 19.4 kB Without provenance Details for blockinfile-2.17.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for blockinfile 2.17.1
File Interpreter ABI Platform Actions
blockinfile-2.17.1-py3-none-any.whl Python 3 none any Details for blockinfile-2.17.1-py3-none-any.whl

Total release size: 40.0 kB

Release files / blockinfile-2.17.1.tar.gz

Download URL blockinfile-2.17.1.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
534efea307c285e2cbde37dff8c133c805787013dff7c680f421a772744f7463
BLAKE2b-256 checksum
How to use checksums
e39ce593b86c466a5f1a656049e5bddf8235c19162f4aa78096cc6767e23f763
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Release files / blockinfile-2.17.1-py3-none-any.whl

Download URL blockinfile-2.17.1-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad52f6dc8bef58f476692ef9df5f16e6fedbfee604753049dcaad4ec6a08f535
BLAKE2b-256 checksum
How to use checksums
8f5e57c61c211d662df0cc5352ed1dce565ef5678e7068607297444406c1421d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.4

Security for blockinfile 2.17.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page