Racing to leave for a trip, but take a look at set_variable_values in the
cfengine_stdlib.cf - it'll take some tweaking, but it has the logic to
"make sure some part of the line that looks 'like' this contains 'that', but
ensure that there are no other lines that contain 'this'.  The logic is all
there.

-Dan

> Ok, I'm thoroughly stumped here. I had something from testing several
> months ago that I thought was doing the right thing, but now I don't
> think it was.
> 
> I want to insert into ~root/.ssh/known_hosts on certain hosts the root
> public ssh key from a trusted root host. But the trickier part is to
> delete any lines from the known_hosts file that match the beginning and
> end of the new key to be added without affecting any other lines. For
> example, say I have
> 
> $(trustedhostkey) = "ssh-dss blahblahblahblah r...@trustedhost"
> 
> and in the local ~root/.ssh/known_hosts file:
> 
> ssh-dss someoldkeytexthere r...@trustedhost
> ssh-dss someotherkeytextab r...@anotherhost
> 
> I just want to replace the first line with $(trustedhostkey) since the
> whole line doesn't match the new key but it does match ssh-dss at the
> beginning and r...@trustedhost at the end. (If the right key is already
> in the file, then it can be left alone.)
> 
> Before I had something like
> 
> vars:
> 
>     "key" string => remotescalar("root_key", "trustedhost", "yes"); #
> yes = encryption
>     "key_fields" slist => splitstring("$(key)", " ", 3)
> 
> delete_lines:
> 
>     "$(key_fields[0]) .* $(key_fields[2])";
> 
> insert_lines:
> 
>     "$(key)";
> 
> But now I've noticed that the indexing of an slist doesn't work. I've
> been playing around with replace_patterns, trying to figure out how I
> might use $(match.N) backrefs, but no success yet.
> 
> Any thoughts on how to do this?
> 
> Thanks,
> Justin
> 
> 
> This electronic communication and any attachments may contain confidential an
> d proprietary 
> information of DigitalGlobe, Inc. If you are not the intended recipient, or a
> n agent or employee 
> responsible for delivering this communication to the intended recipient, or i
> f you have received 
> this communication in error, please do not print, copy, retransmit, dissemina
> te or 
> otherwise use the information. Please indicate to the sender that you have re
> ceived this 
> communication in error, and delete the copy you received. DigitalGlobe reserv
> es the 
> right to monitor any electronic communication sent or received by its employe
> es, agents 
> or representatives.
> 
> _______________________________________________
> 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