ansible.builtin.win_xml (v2.7.7) — module

Add XML fragment to an XML parent

| "added in version" 2.7 of ansible.builtin"

Authors: Richard Levenberg (@richardcs)

preview | supported by community

Install Ansible via pip

Install with pip install ansible==2.7.7

Description

Adds XML fragments formatted as strings to existing XML on remote servers.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Apply our filter to Tomcat web.xml
- win_xml:
   path: C:\apache-tomcat\webapps\myapp\WEB-INF\web.xml
   fragment: '<filter><filter-name>MyFilter</filter-name><filter-class>com.example.MyFilter</filter-class></filter>'
   xpath: '/*'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Apply sslEnabledProtocols to Tomcat's server.xml
- win_xml:
   path: C:\Tomcat\conf\server.xml
   xpath: '//Server/Service[@name="Catalina"]/Connector[@port="9443"]'
   attribute: 'sslEnabledProtocols'
   fragment: 'TLSv1,TLSv1.1,TLSv1.2'
   type: attribute

Inputs

    
path:
    aliases:
    - dest
    - file
    description:
    - The path of remote servers XML.
    required: true

type:
    choices:
    - element
    - attribute
    - text
    default: element
    description:
    - The type of XML you are working with.
    required: true

xpath:
    description:
    - The node of the remote server XML where the fragment will go.
    required: true

backup:
    default: 'no'
    description:
    - Whether to backup the remote server's XML before applying the change.
    type: bool

fragment:
    aliases:
    - xmlstring
    description:
    - The string representation of the XML fragment to be added.
    required: true

attribute:
    description:
    - The attribute name if the type is 'attribute'. Required if C(type=attribute).

Outputs

backup:
  description: name of the backup file, if created
  returned: changed
  sample: C:\config.xml.19700101-000000
  type: string
err:
  description: xml comparison exceptions
  returned: always, for type element and -vvv or more
  sample: attribute mismatch for actual=string
  type: list
msg:
  description: what was done
  returned: always
  sample: xml added
  type: string