Feature: make files.blockinfile more consistent with Ansible

Open
#1,602 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
ansible, python

Research direction

Start by reviewing issue #1477 and the existing files.line, files.blockinfile, files.template, and files.directory operations, along with the linked Ansible lineinfile documentation. Resolve whether an alias and parameter harmonization are wanted, then define a concrete compatibility scope; the issue is done when those decisions and the resulting changes are agreed and implemented.

Written by the indexing model from the issue text.

Description

operations spec

Following the comments in #1477, for files.line this issue summarizes the differences between pyinfra and Ansible and proposes changes.

Summaries and proposals for blockinfile and template will follow if this is useful.

The first question is whether or not to add files.lineinfile as an alias for files.line and if so, whether or not to deprecate files.line ? The second question is if the alias is added, are the parameter names harmonized in the newly added alias as given the differences visible in the table below, the difference in names seems to be a good hint things are not identical.

Opinions ?

The third question is how do the parameters compare. The table below compares pyinfra's files.line to Ansible's lineinfile and proposes updates to files.line. Ansible's parameter aliases have been ignored in the analysis.

Ansible pyinfra Purpose Proposal
attributes none file system attributes for chattr do not add [1]
backrefs interpolate_variables populate references in line from values found by regex exists
backup backup whether to backup the file exists
create none controls whether file created if it doesn't exist add [2]
encoding none character set in which file is encoded do not add [1]
none ensure_newline ensure the appended line is on a new line n/a
none escape_regex_characters escape regex characters from the matching line n/a
firstmatch none used with insertafter/before do not add [3]
none flags flags to be passed to sed n/a
group none filesystem group for chown add [4]
insertafter none where to insert the line do not add [3]
insertbefore none where to insert the line do not add [3]
line replace the line/template to insert/replace exists
mode none the filesystem permissions add [4]
owner none filesystem owner for chown add [4]
path path file to modify exists
regex line the pattern to look for exists
search_string line the literal string to look for do not add [5]
selevel none the SELinux MLS/MCS do not add [1]
serole none the SELinux role do not add [1]
setype none the SELinux type do not add [1]
seuser none the SELinux seuser do not add [1]
state present whether the line should be present or not no change - most (all ?) other pyinfra operations use present
unsafe_writes none whether unsafe writes are permitted if necessary do not add [1]
validate none the validation command to run after the file is updated do not add [1]

[1] none of the operations in pyinfra have these attributes so any change should be made pyinfra-wide and not only in these three operations
[2] should save some repeated checking
[3] defer as this likely would require awk and thus complexity similar to that found in files.blockinfile
[4] should save some extra operation invocations and files.directory already supports this
[5] use line and escape_regex_characters to get the same result

Dominant language
Python
Stars
6k
Forks
548
Avg merge
7d 17h
Merged PRs (30d)
13

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pyinfra-dev/pyinfra

All issues in pyinfra-dev/pyinfra

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.