Ansible XML来配置Jira Server.xml

问题描述

当前,我正在尝试使用ansible更改“ server.xml”文件中的字段。具体来说,在“连接器”元素中列出的选项。我发布了一个示例“ server.xml”,其中更改了字段内容以删除标识信息。

<?xml version="1.0" encoding="utf-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

<Service name="Catalina">

               <Connector port="8080" proxyName="test.somewebsite.com" proxyport="443" scheme="https" secure="true" relaxedPathChars="[]|" relaxedQueryChars="[]|{}^&#x5c;&#x60;&quot;&lt;&gt;"
               maxThreads="150" minSpareThreads="25" connectionTimeout="20000" enableLookups="false"
               maxHttpHeaderSize="8192" protocol="HTTP/1.1" useBodyEncodingForURI="true" redirectPort="8443"
               acceptCount="100" disableUploadTimeout="true" bindOnInit="false"/>


    <Engine name="Catalina" defaultHost="localhost">
        <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">

            <Context path="" docBase="${catalina.home}/atlassian-jira" reloadable="false" useHttpOnly="true">
                <Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction"
                          factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/>
                <Manager pathname=""/>
                <JarScanner scanManifest="false"/>
            </Context>

        </Host>
        <Valve className="org.apache.catalina.valves.AccessLogValve"
               pattern="%a %{jira.request.id}r %{jira.request.username}r %t &quot;%m %U%q %H&quot; %s %b %D &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot; &quot;%{jira.request.assession.id}r&quot;"/>
    </Engine>
</Service>

我正在使用以下Ansible进行更改。我的大部分调整将在连接器属性上执行,例如更改代理名称或将其完全删除。不幸的是,我发现唯一的相似之处是名称空间,但是此代码未使用常规名称空间。我在做什么错了?

- hosts: localhost

  tasks:
  - name: Update Scheme Option in Connector
    xml:
      path: /home/test/server.xml
      xpath: /Server/Service/Connector/@scheme
      value: https

  - name: Update Secure Option in Connector
    xml:
      path: /home/test/server.xml
      xpath: /Server/Service/Connector/@secure
      value: true


  - name: Remove the Unused attributes
    xml:
      path: /home/test/server.xml
      xpath: "{{ item }}"
      state: absent
    loop:
      - "/Server/Service/Connector/@proxyName"
      - "/Server/Service/Connector/@proxyport"
      - "/Server/Service/Connector/@secure"
      - "/Server/Service/Connector/@redirectPort"

解决方法

根据documentation,在使用attribute进行设置时,必须在单独的value选项中提供属性名称。另请注意,true值必须用引号引起来,否则您将收到一个python错误,抱怨您传递的是bool而不是字符串

这是您的固定任务集:

  tasks:
  - name: Update Scheme Option in Connector
    xml:
      path: /home/test/server.xml
      xpath: /Server/Service/Connector
      attribute: scheme
      value: https

  - name: Update Secure Option in Connector
    xml:
      path: /home/test/server.xml
      xpath: /Server/Service/Connector
      attribute: secure
      value: "true"

  - name: Remove the Unused attributes
    xml:
      path: /home/test/server.xml
      xpath: "{{ item }}"
      state: absent
    loop:
      - "/Server/Service/Connector/@proxyName"
      - "/Server/Service/Connector/@proxyport"
      - "/Server/Service/Connector/@secure"
      - "/Server/Service/Connector/@redirectPort"

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...