win_xml module for manipulating XML files on Windows (#26404)

documentation fixups

handling backup in a more ansible canonical way

remove quotes from $dest

Handle elements with only text child nodes
This commit is contained in:
Richard Levenberg 2018-08-30 19:20:09 -07:00 committed by Jordan Borean
parent 113336d6f1
commit c759381b0b
7 changed files with 458 additions and 0 deletions

View file

@ -0,0 +1 @@
shippable/windows/group1

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<config>
<string key="foo">bar</string>
</config>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
<appender name="stdout" class="org.apache.log4j.ConsoleAppender" >
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%d{dd/MM/yy hh:mm:ss:sss z}] %5p %c{2}: %m%n"/>
</layout>
</appender>
<appender name="file" class="org.apache.log4j.DailyRollingFileAppender">
<param name="append" value="true" />
<param name="encoding" value="UTF-8" />
<param name="file" value="mylogfile.log" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="[%-25d{ISO8601}] %-5p %x %C{1} -- %m\n" />
</layout>
</appender>
<logger name="org.springframework.security.web.FilterChainProxy" additivity="false">
<level value="error"/>
<appender-ref ref="file" />
</logger>
<logger name="org.springframework.security.web.context.HttpSessionSecurityContextRepository" additivity="false">
<level value="error"/>
<appender-ref ref="file" />
</logger>
<logger name="org.springframework.security.web.context.SecurityContextPersistenceFilter" additivity="false">
<level value="error"/>
<appender-ref ref="file" />
</logger>
<logger name="org.springframework.security.web.access.intercept" additivity="false">
<level value="error"/>
<appender-ref ref="stdout" />
</logger>
<logger name="org.apache.commons.digester" additivity="false">
<level value="info"/>
<appender-ref ref="stdout" />
</logger>
<root>
<priority value="debug"/>
<appender-ref ref="stdout"/>
</root>
</log4j:configuration>

View file

@ -0,0 +1,2 @@
dependencies:
- prepare_win_tests

View file

@ -0,0 +1,73 @@
# test code for the Windows xml module
# (c) 2017, Richard Levenberg <richard.levenberg@cosocloud.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: copy a test .xml file
win_copy:
src: config.xml
dest: "{{win_output_dir}}\\config.xml"
- name: add an element that only has a text child node
win_xml:
path: "{{win_output_dir}}\\config.xml"
fragment: '<string key="answer">42</string>'
xpath: '/config'
register: element_add_result
- name: check element add result
assert:
that:
- element_add_result is changed
- name: try to add the element that only has a text child node again
win_xml:
path: "{{win_output_dir}}\\config.xml"
fragment: '<string key="answer">42</string>'
xpath: '/config'
register: element_add_result_second
- name: check element add result
assert:
that:
- not element_add_result_second is changed
- name: copy a test log4j.xml
win_copy:
src: log4j.xml
dest: "{{win_output_dir}}\\log4j.xml"
- name: change an attribute to fatal logging
win_xml:
path: "{{win_output_dir}}\\log4j.xml"
xpath: '/log4j:configuration/logger[@name="org.apache.commons.digester"]/level'
type: attribute
attribute: 'value'
fragment: 'FATAL'
- name: try to change the attribute again
win_xml:
path: "{{win_output_dir}}\\log4j.xml"
xpath: '/log4j:configuration/logger[@name="org.apache.commons.digester"]/level'
type: attribute
attribute: 'value'
fragment: 'FATAL'
register: attribute_changed_result
- name: check attribute change result
assert:
that:
- not attribute_changed_result is changed