Hello
I’m struggling to find a solution to removing multiple lines from a js file thousands of rows long.
I can’t use markers for blockinfile since after a version update, the function may be somewhere else and the markers will be gone then and I can’t use a fixed position either, since this could also change then.
I have tried lineinfile and replace modules and the regex that would work in regex101.com in Python flavor will either error out or show it’s already ok, nothing was changed.
I have tried complex patterns to make absolutely sure I won’t delete anything by accident, but I’m at the moment at this very simple, yet more dangerous pattern and Ansible says it’s already ok.
- name: Remove the subscription box from the Datacenter Summary page.
ansible.builtin.lineinfile:
path: /root/test.js
regexp: '^\s+?{\n\s+title: gettext\(''Subscriptions''\),.*(\n.+){17}'
state: absent
A more strict, but more complex pattern that matches every line in the block was:
^\s+?{\n\s+?title: gettext\(''Subscriptions''\),\n(\s+?(height|items).+?\n){2}\s+?{\n(\s+?(xtype|itemId|userCls|listeners|element|click).+?\n){6}\s+?if\s\(.+?\n\s+?window\.open.+?\n\s+?}\n.+?\n(\s+?},\n){2}\s+?],\n\s+?},
Wrapped regex around double quotes instead of single quotes and the pattern would look like this, but it still says everything is ok:
^\\s+?{\\n\\s+?title: gettext\\('Subscriptions'\\),\\n(\\s+?(height|items).+?\\n){2}\\s+?{\\n(\\s+?(xtype|itemId|userCls|listeners|element|click).+?\\n){6}\\s+?if\\s\\(.+?\\n\\s+?window\\.open.+?\\n\\s+?}\\n.+?\\n(\\s+?},\\n){2}\\s+?],\\n\\s+?},
Is there even a way to do this with Ansible natively?
Basically I’m trying to remove the following lines from pvemanagerlib.js.
{
title: gettext('Subscriptions'),
height: 220,
items: [
{
xtype: 'pveHealthWidget',
itemId: 'subscriptions',
userCls: 'pointer',
listeners: {
element: 'el',
click: function() {
if (this.component.userCls === 'pointer') {
window.open('https://www.proxmox.com/en/proxmox-virtual-environment/pricing', '_blank');
}
},
},
},
],
},
Don’t panic, I’m running Proxmox at home and their subscription is way too expensive for what I do with it and I started using it last month. I want to clean up the Datacenter Summary page.