Search and replace

16 views
Skip to first unread message

thierry thunot

unread,
Jul 5, 2021, 12:03:26 AM7/5/21
to help-cfengine

hello all,

I have another problem ;)
I tried to search lines and replace with values in a proxmox file, part of this file:

...

 success: function(response, opts) {
                    let res = response.result;
                    if (res === null || res === undefined || !res || res
                        .data.status.toLowerCase() !== 'active') {
                        Ext.Msg.show({
                            title: gettext('No valid subscription'),

                            icon: Ext.Msg.WARNING,
                            message: Proxmox.Utils.getNoSubKeyHtml(res.data.url),
                            buttons: Ext.Msg.OK,
                            callback: function(btn) {
                                if (btn !== 'ok') {
....

Note that Ext.Msg.show is repeated several times in the file but I only have to change this occurrence

i need to change it by :

 success: function(response, opts) {
                    let res = response.result;
                    if (res === null || res === undefined || !res || res
                        .data.status.toLowerCase() !== 'active') {
                        void{//Ext.Msg.show({
                            title: gettext('No valid subscription'),

                            icon: Ext.Msg.WARNING,
                            message: Proxmox.Utils.getNoSubKeyHtml(res.data.url),
                            buttons: Ext.Msg.OK,
                            callback: function(btn) {
                                if (btn !== 'ok') {


i try this bundle whitout success
bundle agent    sys_conf_proxmox
{
        methods:
        pve2::
        "any" usebundle => supp_message_subscription;

}
bundle agent    supp_message_subscription
{
        vars:
        "msg_a_remplacer" string => "Ext.Msg.show({
                  title: gettext('No valid subscription'),";
        "msg_remplacant" string => "void({ //Ext.Msg.show({
                            title: gettext('No valid subscription'),";
        "fic_conf_pve" string => "/usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js";
        files:
        "$(fic_conf_pve)"
        edit_line => remplacement_ligne($(msg_a_remplacer),$(msg_remplacant),all),
        edit_defaults => levee_limite_fic,
        comment => "Supression subscription pve",
        classes => if_repaired(relance_web_pve),
        action => if_elapsed(60);

        services:
        "pveproxy.service"
                service_policy => "restart";


}
      body edit_defaults levee_limite_fic
     {
                  max_file_size => "500K";
                       }
bundle edit_line remplacement_ligne(a_remplacer,remplacant,nb_occurences)
{
        replace_patterns:
        "$(a_remplacer)"
        replace_with => ligne_text($(remplacant),$(nb_occurences));

        }

Thanks for your replies ;)

Nick Anderson

unread,
Jul 13, 2021, 6:06:41 PM7/13/21
to thierry thunot, help-cfengine

thierry thunot <tth...@gmail.com> writes:

Hi Thierry,

If the line you are replacing exists in the file mutliple times and you only want to target one of them, then I think you will need to use select_region so that you are editing the one you want.

https://docs.cfengine.com/docs/3.18/reference-promise-types-files-edit_line.html#select_region

Is this file pretty unique per host? If it's not, I would probably recommend full file management like a mustache template or a copy_from.

Reply all
Reply to author
Forward
0 new messages