Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineInFile: New resource proposal #29

Open
wildmichael opened this issue Feb 7, 2019 · 3 comments
Open

LineInFile: New resource proposal #29

wildmichael opened this issue Feb 7, 2019 · 3 comments
Labels
help wanted The issue is up for grabs for anyone in the community. resource proposal The issue is proposing a new resource in the resource module.

Comments

@wildmichael
Copy link

wildmichael commented Feb 7, 2019

Description

Many file formats do not match the pre-made assumptions of this module. E.g. the KeyValuePairFile resource almost matches my current requirement, however in my case the key and value should be separated by a colon, not an equal sign. This resource would be more general as it would allow the user to specify the line contents (Text) and a regex to determine whether the line is already present. The proposal is modeled after the lineinfile module in Ansible, however in a simplified form. More options (like InsertBefore, InsertAfter, FirstMatch, Backrefs, Backup, etc) could be added if deemed necessary.

Proposed properties

  • Path: The file to modify.
  • Create: Whether the file should be created if not present (if Ensure = 'Present').
  • Text: The line to insert (if Ensure = 'Present')
  • Regex: The regular expression to find the line to modify. If Ensure = 'Present' the regular expression should match the state before and after modification to ensure idempotence. If Ensure = 'Absent' it will be used to determine whether the line needs to be removed. Only the last found instance will be modified.

Special considerations or limitations

None that I could see.

@johlju
Copy link
Member

johlju commented Feb 8, 2019

What would be the key(s) in this resource?

Maybe we should add a property for the InsertType where it in a first iteration can only have single InsertAfter value? But rather they are all considered so we can find potential limitations.

Also, maybe we could add a optional property Line which could be an array of numbers, to just say that it should insert the text at a specific line(s)?

@wildmichael
Copy link
Author

Line numbers are a fickle thing. I would rather make InsertAfter and InsertBefore regular expressions, that should cover most cases. What do you mean by keys (sorry if this is a stupid question, I'm quite new to DSC)?

@PlagueHO PlagueHO added resource proposal The issue is proposing a new resource in the resource module. help wanted The issue is up for grabs for anyone in the community. labels Feb 9, 2019
@johlju
Copy link
Member

johlju commented Feb 9, 2019

I meant that both line numbers and regular expression could be used (mutually exclusively).

There are no such question, all questions are welcome! :)
If you look at this schema.mof (link below), there are two properties that has the type qualifier Key. There can only be one instance of a configuration with the same key’s that uniquely separates it from another configuration, so that two configuration instances can’t change the same thing.
I hope I explained it well enough 😄

https://github.com/PlagueHO/FileContentDsc/blob/dev/DSCResources/DSR_KeyValuePairFile/DSR_KeyValuePairFile.schema.mof

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted The issue is up for grabs for anyone in the community. resource proposal The issue is proposing a new resource in the resource module.
Projects
None yet
Development

No branches or pull requests

3 participants