Jesse, I could propose to replace field_edits with file_edits, for example, generic (library ready) body:
bundle edit_line etc_fstab(device,mpoint,fstype,opts,passes) { classes: "already_there" expression => regline("$(device)\s+$(mpoint)\s+$(fstype)\s+$(opts)\s+$(passes)", "$(edit.filename)"); !already_there:: "device_match" expression => regline("$(device)\s+.*", "$(edit.filename)"); "mpoint_match" expression => regline(".*\s+$(mpoint)\s+.*", "$(edit.filename)"); delete_lines: device_match:: "$(device)\s+.*" comment => "Wrong mountpoint, or fstype, or options"; mpoint_match:: ".*\s+$(mpoint)\s+.*" comment => "Mountpoint misused"; insert_lines: !already_there:: "$(device) $(mpoint) $(fstype) $(opts) $(passes)"; } 2010/12/2 Jesse Becker <becker...@mail.nih.gov>: > I have a file (/etc/fstab) with well defined fields and > subfields, and am trying to edit one of the fields, including removing > duplicate entries. > > > Here's the original line in question: > > /dev/md2 /scratch ext3 defaults 1 2 > > Here's what I want it to look like at the end: > > /dev/md2 /scratch ext3 usrquota,grpquota 1 2 > > > Due to an oddly non-convergent (?!) set of field_edits, I have a line > that looks like this: > > /dev/md2 /scratch ext3 > usrquota,grpquota,usrquota,grpquota,usrquota,grpquota 1 2 > > > As I see it, I originally needed to do two things: > > 1) Add the two options passed to field #4. > 2) Delete the "default" subfield value, if it exists. > > For some reason, the values in #1 are appended repeatedly, even if they > already exist in that field. The 'default' value is removed correctly > > > Here is the code that I'm using (the "col" body comes from the stdlib): > > bundle scratch { > files: > scratch_hosts:: > "/etc/fstab" > edit_line => add_mount_options('/scratch','usrquota,grpquota'), > handle => 'scratch_add_quotas_for_scratch_to_fstab', > classes => trigger('scratch_added_quota'); > } > > bundle edit_line add_mount_options(filesystem,options) { > > field_edits: > > "^.*\s+${filesystem}\s+.*(usrquota,grpquota,usrquota,grpquota,?)+.*$" > edit_field => col('\s+',4,"(usrquota,grpquota,)+",'delete'), > comment => "Remove duplicate urgquota,grpquota entries"; > > > "^.*\s+${filesystem}\s+.*$" > edit_field => col('\s+',4,"${options}",'append'), > comment => "Add options to fstab column 4"; > > > "^.*\s+${filesystem}\s+.*defaults.*$" > edit_field => col('\s+',4,'defaults','delete'), > comment => "Remove default option"; > > } > > > > Here is the relevant output from running under --verbose (this is > version 3.0.5p1): > > > > > cf3 ========================================================= > cf3 files in bundle scratch (1) > cf3 ========================================================= > cf3 > cf3 Verifying SQL table promises is only available with Cfengine Nova or above > cf3 > cf3 ......................................................... > cf3 Promise handle: scratch_add_quotas_for_scratch_to_fstab > cf3 Promise made by: /etc/fstab > cf3 ......................................................... > cf3 > cf3 -> Using literal pathtype for /etc/fstab > cf3 -> Handling file existence constraints on /etc/fstab > cf3 -> Handling file edits in edit_line bundle add_mount_options > cf3 > cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > cf3 BUNDLE add_mount_options( {'/scratch','usrquota'} ) > cf3 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * > cf3 > cf3 ? Augment scope add_mount_options with filesystem > cf3 ? Augment scope add_mount_options with options > cf3 ?? Private class context > cf3 > cf3 > cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = > cf3 field_edits in bundle add_mount_options > cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = > cf3 > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: > ^.*\s+/scratch\s+.*(usrquota,grpquota,usrquota,grpquota,?)+.*$ > cf3 > cf3 Comment: Remove duplicate urgquota,grpquota entries > cf3 ......................................................... > cf3 > cf3 - Matched line (/dev/md2 /scratch ext3 > usrquota,grpquota,usrquota,grpquota,usrquota,grpquota 1 > 2) > cf3 -> Stopped at field 4 > cf3 -> No need to edit field in /etc/fstab > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: ^.*\s+/scratch\s+.*$ > cf3 > cf3 Comment: Add options to fstab column 4 > cf3 ......................................................... > cf3 > cf3 - Matched line (/dev/md2 /scratch ext3 > usrquota,grpquota,usrquota,grpquota,usrquota,grpquota 1 > 2) > cf3 -> Stopped at field 4 > cf3 -> No need to edit field in /etc/fstab > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: ^.*\s+/scratch\s+.*defaults.*$ > cf3 > cf3 Comment: Remove default option > cf3 ......................................................... > cf3 > cf3 ?? Private class context > cf3 > cf3 > cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = > cf3 field_edits in bundle add_mount_options > cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = > cf3 > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: > ^.*\s+/scratch\s+.*(usrquota,grpquota,usrquota,grpquota,?)+.*$ > cf3 > cf3 Comment: Remove duplicate urgquota,grpquota entries > cf3 ......................................................... > cf3 > cf3 -> This promise has already been verified > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: ^.*\s+/scratch\s+.*$ > cf3 > cf3 Comment: Add options to fstab column 4 > cf3 ......................................................... > cf3 > cf3 -> This promise has already been verified > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: ^.*\s+/scratch\s+.*defaults.*$ > cf3 > cf3 Comment: Remove default option > cf3 ......................................................... > cf3 > cf3 -> This promise has already been verified > cf3 ?? Private class context > cf3 > cf3 > cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = > cf3 field_edits in bundle add_mount_options > cf3 = = = = = = = = = = = = = = = = = = = = = = = = = = = = > cf3 > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: > ^.*\s+/scratch\s+.*(usrquota,grpquota,usrquota,grpquota,?)+.*$ > cf3 > cf3 Comment: Remove duplicate urgquota,grpquota entries > cf3 ......................................................... > cf3 > cf3 -> This promise has already been verified > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: ^.*\s+/scratch\s+.*$ > cf3 > cf3 Comment: Add options to fstab column 4 > cf3 ......................................................... > cf3 > cf3 -> This promise has already been verified > cf3 > cf3 ......................................................... > cf3 Promise handle: > cf3 Promise made by: ^.*\s+/scratch\s+.*defaults.*$ > cf3 > cf3 Comment: Remove default option > cf3 ......................................................... > cf3 > cf3 -> This promise has already been verified > cf3 -> No edit changes to file /etc/fstab need saving > cf3 > > > (Nothing is done in iterations 2 and 3). > > > > Thanks in advance. > > -- > Jesse Becker > NHGRI Linux support (Digicon Contractor) > _______________________________________________ > Help-cfengine mailing list > Help-cfengine@cfengine.org > https://cfengine.org/mailman/listinfo/help-cfengine > -- SY, Seva Gluschenko. _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine