This should be possible, but it's going to be messy to do it all with
edit_line bundles. I think this is better handled with templates or
pulling the entire file into cfengine for distribution.

2009/11/27  <nwat...@symcor.com>:
> I'm experimenting with inserting a block of lines and need some guidance.
> Found in my target file is:
> if [ `id -u` -gt 99 ]; then
>        umask 027
> else
>        umask 022
> fi
>
> My policy:
> ####################
> body common control {
>
>    inputs => { "library.cf" };
>        bundlesequence => { "test" };
> }
>
> bundle agent test {
>
>    vars:
>
>        "trg" string => "/tmp/profile",
>        comment => "Target file to search.";
>
>        "umask" string =>
> "
>  if [ `id -u` -gt 99 ]; then
>     umask 027
>  else
>     umask 022
>  fi
> ",
>        comment => "Umask settings.";
>
>    files:
>
>        "${trg}"
>            edit_line => insert_lines_warn_only("${umask}", "${trg}"),
>            comment => "Delete any ${dstr} and insert with one ${istr}";
> }
>
> bundle edit_line insert_lines_warn_only(str, trg){
>
>    insert_lines:
>        "${str}",
>        action => warn_now,
>        comment => "Insert multiline string into ${trg}.";
> }
>
> Output from this policy is follows:
> [nwat...@configa01 inputs]$ ../bin/cf-agent -Kf ./grepfile.cf
>  -> Need to insert line " if [ `id -u` -gt 99 ]; then" in /tmp/profile but
> only a warning was promised
> I: Made in version 'not specified' of './grepfile.cf' near line 51
> I: Comment: Insert multiline string into /tmp/profile.
>
>  -> Need to insert line "     umask 027" in /tmp/profile but only a
> warning was promised
> I: Made in version 'not specified' of './grepfile.cf' near line 51
> I: Comment: Insert multiline string into /tmp/profile.
>
>  -> Need to insert line " else" in /tmp/profile but only a warning was
> promised
> I: Made in version 'not specified' of './grepfile.cf' near line 51
> I: Comment: Insert multiline string into /tmp/profile.
>
>  -> Need to insert line "     umask 022" in /tmp/profile but only a
> warning was promised
> I: Made in version 'not specified' of './grepfile.cf' near line 51
> I: Comment: Insert multiline string into /tmp/profile.
>
>  -> Need to insert line " fi" in /tmp/profile but only a warning was
> promised
> I: Made in version 'not specified' of './grepfile.cf' near line 51
> I: Comment: Insert multiline string into /tmp/profile.
>
> Am I on the right track?  Since the lines are already in the target file
> why does the policy decide that insertion is needed?  How can the policy
> account for leading or trailing whitespace that is technically
> unimportant?
>
> Sincerely,
> --
> Neil Watson
> 416-673-3465
>
>
>
> CONFIDENTIALITY WARNING
> This communication, including any attachments, is for the exclusive use of 
> addressee and may contain proprietary and/or confidential information. If you 
> are not the intended recipient, any use, copying, disclosure, dissemination 
> or distribution is strictly prohibited. If you are not the intended 
> recipient, please notify the sender immediately by return e-mail, delete this 
> communication and destroy all copies.
>
> AVERTISSEMENT RELATIF À LA CONFIDENTIALITÉ
> Ce message, ainsi que les pièces qui y sont jointes, est destiné à l’usage 
> exclusif de la personne à laquelle il s’adresse et peut contenir de 
> l’information personnelle ou confidentielle. Si le lecteur de ce message n’en 
> est pas le destinataire, nous l’avisons par la présente que toute diffusion, 
> distribution, reproduction ou utilisation de son contenu est strictement 
> interdite. Veuillez avertir sur-le-champ l’expéditeur par retour de courrier 
> électronique et supprimez ce message ainsi que toutes les pièces jointes.
>
> _______________________________________________
> Help-cfengine mailing list
> Help-cfengine@cfengine.org
> https://cfengine.org/mailman/listinfo/help-cfengine
>
>
_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to