Augeas with XML files

Augeas can edit a number of different file formats, but here we'll cover XML.

Augeas with augtool

1) Define a XML file to play with:
$ cat /tmp/foo.xml
   <FooBar foo="bar">2</FooBar>
      <Bar foo="bar">foo</Bar>
      <Lol />

2) Start augtool:

$augtool --noload --noautoload --echo

3) Set XML lens:

augtool> set /augeas/load/xml/lens "Xml.lns"
augtool> set /augeas/load/xml/incl "/tmp/foo.xml"
augtool> load

4) Print internal tree:

augtool> print /files
/files/tmp/foo.xml/TopLevel/#text[1] = "\n\t"
/files/tmp/foo.xml/TopLevel/FooBar/#attribute/foo = "bar"
/files/tmp/foo.xml/TopLevel/FooBar/#text = "2"
/files/tmp/foo.xml/TopLevel/#text[2] = "\t"
/files/tmp/foo.xml/TopLevel/Foo/#text[1] = "\n\t\t"
/files/tmp/foo.xml/TopLevel/Foo/Bar/#attribute/foo = "bar"
/files/tmp/foo.xml/TopLevel/Foo/Bar/#text = "foo"
/files/tmp/foo.xml/TopLevel/Foo/#text[2] = "\t\t"
/files/tmp/foo.xml/TopLevel/Foo/Lol = "#empty"
/files/tmp/foo.xml/TopLevel/Foo/#text[3] = "\t"

5) Define a attribute, and a value for the element. First, you have to remove the #empty value for Lol, then you have to set the attribute, and then the value (in that order)

augtool> set /files/tmp/foo.xml/TopLevel/Foo/Lol
augtool> set /files/tmp/foo.xml/TopLevel/Foo/Lol/#attribute/jk "abc"
augtool> set /files/tmp/foo.xml/TopLevel/Foo/Lol/#text "def"

6) Verify changes:

augtool> print /files
/files/tmp/foo.xml/TopLevel/Foo/Lol/#attribute/jk = "abc"
/files/tmp/foo.xml/TopLevel/Foo/Lol/#text = "def"

7) Flush changes to disk:

augtool> save

Augeas with puppet

Case: We want to ensure the following in /var/lib/jenkins/config.xml:
  <securityRealm class="org.jenkinsci.plugins.reverse_proxy_auth.ReverseProxySecurityRealm" plugin="reverse-proxy-auth-plugin@1.4.0">

In puppet, we use the aegan type. Here, we choose to store the main configuration in the manifest file, and the bulk of the commands in hieradata.


# We use the 'augeas' type to set certain kind of information in
# the jenkins configuration files
augeas{ "jenkins_config":
  incl => "/var/lib/jenkins/config.xml",
  lens => "Xml.lns",
  context => "/files/var/lib/jenkins/config.xml/hudson",
  changes => hiera('augeas_changes', [])

# # # # #

  - 'set useSecurity/#text true'
  - 'set slaveAgentPort/#text 9090'
  - 'set securityRealm/#attribute/class org.jenkinsci.plugins.reverse_proxy_auth.ReverseProxySecurityRealm'
  - 'set securityRealm/#attribute/plugin reverse-proxy-auth-plugin@1.4.0'
  - 'set securityRealm/inhibitInferRootDN/#text false'
  - 'set securityRealm/userSearch/#text uid={0}'
  - 'set securityRealm/updateInterval/#text 15'
  - 'set securityRealm/forwardedUser/#text ADFS_LOGIN'
  - 'set securityRealm/headerGroups/#text ADFS_GROUP'
  - 'set securityRealm/headerGroupsDelimiter/#text ;'
  - 'clear securityRealm/proxyTemplate'
  - 'clear securityRealm/authContext'
  - 'clear securityRealm/authorityUpdateCache'
  - 'clear securityRealm/userSearchBase'
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r3 - 2014-07-25 - TerjeAndersen
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback