xmlpuppetaugeas

Puppet XML augeas lens


I'm trying to set the configuration for a Windows CFG file with Puppet.

augeas{ "bbdisplay_setting":
  incl => '/tmp/BBWin.cfg',
  lens => "Xml.lns",
  # How do I change the value of `value=1.1.1.1 to value=9.9.9.9
}

I can't find a good example of how to change the value of the first bbdisplay in this example XML file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <bbwin>
    <setting name="bbdisplay" value="1.1.1.1" />
    <setting name="bbdisplay" value="2.2.2.2" />
  </bbwin>
</configuration>

Augtool lists the config as:

/files
/files/tmp
/files/tmp/BBWin.cfg
/files/tmp/BBWin.cfg/#declaration
/files/tmp/BBWin.cfg/#declaration/#attribute
/files/tmp/BBWin.cfg/#declaration/#attribute/version = "1.0"
/files/tmp/BBWin.cfg/#declaration/#attribute/encoding = "utf-8"
/files/tmp/BBWin.cfg/configuration
/files/tmp/BBWin.cfg/configuration/#text = "\n  "
/files/tmp/BBWin.cfg/configuration/bbwin
/files/tmp/BBWin.cfg/configuration/bbwin/#text[1] = "\n"
/files/tmp/BBWin.cfg/configuration/bbwin/setting[1] = "#empty"
/files/tmp/BBWin.cfg/configuration/bbwin/setting[1]/#attribute
/files/tmp/BBWin.cfg/configuration/bbwin/setting[1]/#attribute/name = "bbdisplay"
/files/tmp/BBWin.cfg/configuration/bbwin/setting[1]/#attribute/value = "1.1.1.1"
/files/tmp/BBWin.cfg/configuration/bbwin/#text[2] = "    "
/files/tmp/BBWin.cfg/configuration/bbwin/setting[2] = "#empty"
/files/tmp/BBWin.cfg/configuration/bbwin/setting[2]/#attribute
/files/tmp/BBWin.cfg/configuration/bbwin/setting[2]/#attribute/name = "bbdisplay"
/files/tmp/BBWin.cfg/configuration/bbwin/setting[2]/#attribute/value = "2.2.2.2"
/files/tmp/BBWin.cfg/configuration/bbwin/#text[3] = "  "

Solution

  • If you want to change the first bbdisplay then:

    augeas{ "bbdisplay_setting":
      incl    => '/tmp/BBWin.cfg',
      lens    => "Xml.lns",
      changes => "set configuration/bbwin/setting[#attribute/name="bbdisplay"][1]/#attribute/value 9.9.9.9",
    }
    

    or another example, to change it by the existing value:

    augeas{ "bbdisplay_setting":
      incl    => '/tmp/BBWin.cfg',
      lens    => "Xml.lns",
      changes => "set configuration/bbwin/setting[#attribute/value = "1.1.1.1"]/#attribute/value 9.9.9.9",
    }