rex-augeas is a (R)?ex module to manage configuration files with libaugeas.
In your Rexfile use the following commands.
use Rex::Augeas;
task "example", sub {
augeas modify =>
"/files/etc/hosts/7/ipaddr" => "10.211.55.6",
"/files/etc/hosts/7/canonical" => "blah01";
augeas remove => "/files/etc/hosts/2";
augeas dump => "/files/etc/hosts";
my $val = augeas exists => "/files/etc/hosts/*/ipaddr", "127.0.0.1";
augeas insert => "/files/etc/hosts",
label => "01",
after => "/7",
ipaddr => "192.168.2.23",
canonical => "mango.linoratix.com",
alias => "mango";
};