win_blockinfile module

Hi all,

do you know of an existing Windows port of the blockinfile module?
Or is anybody already working on it?

If not, I’d like to go ahead and create a win_blockinfile module.

Greets,
Alex

Just catching up with the group messages. I haven’t heard of anyone doing this, so I reckon go ahead.
I would just make sure you can’t already do what you need using template / win_template before spending your time on this though.

Jon

Hi Joe,

thanks for your reply and sorry that I am catching up so late.

I thought about using win_template but I does not work for me, as I do not have all the necessary input at that point to assemble the whole file myself. It would require shifting quite some application knowledge which is just not feasible (yet).
Nevertheless, thanks for the suggestion.

Instead I started working on the win_blockinfile module. It is basically a Windows port of the existing blockinfile Unix module. Some features are stripped like the permission stuff or the validation of the modified file.
For the backup functionality I was looking for a powershell helper function for creating backups like there is with the python method AnsibleModule#backup_local (basic.py). I currently copied the function win_lineinfile#BackupFile, which I do not like at all. Is there a central location for utility powershell functions like this?
On your ‘Developing Modules’ page in appendix ‘Module Utilities’ you list a bunch of python utilities but only one powershell utility file: powershell.ps1.
Is there anything else? Could you give me some advice here?

Anyway, I progressed quite far. Most of the implementation is done, tests as well…

Greets,
Alex

Hi Alex!

I really appreciate if you can share your module.

I couldn’t find any solution to my problem of block insertion in arbitrary existing file on windows host.

Sure, I can share it on Github.
It was developed quite some time ago and was using lineinfile windows module as a basis.
It is working and actively used but some things are missing:

  • Check fixes to lineinfile module and see if they are relevant for blockinfile
  • Tests probably need to be updated

I always wanted to share it, so maybe we can move it forward together.
I will post the Github link once I’ve shared it.