win_blockinfile module

883 views
Skip to first unread message

Alexander Lüders

unread,
Nov 29, 2016, 1:18:23 PM11/29/16
to Ansible Development
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

jhawkesworth

unread,
Dec 6, 2016, 4:18:48 AM12/6/16
to Ansible Development
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

Alexander Lüders

unread,
Dec 31, 2016, 4:27:34 AM12/31/16
to Ansible Development
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

Максим Прокопов

unread,
May 16, 2019, 11:00:06 AM5/16/19
to Ansible Development
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.

суббота, 31 декабря 2016 г., 12:27:34 UTC+3 пользователь Alexander Lüders написал:

Alexander Lüders

unread,
May 22, 2019, 1:40:18 PM5/22/19
to Ansible Development
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.
Reply all
Reply to author
Forward
0 new messages