Ansible 无法解析模块/操作“community.general.xml”

问题描述 投票:0回答:1

我希望使用ansible的

community.general.xml
模块来解析xml。

ansible playbook 主机(运行程序)是 OLAM EE 环境(Oracle Linux 自动化管理器)提供的 docker 容器,不属于我的团队。

在使用如下所示的

xml
模块之前,我尝试在剧本中安装社区常规。

    - name: Install general
      shell: ansible-galaxy collection install community.general
      become_user: root
      delegate_to: localhost
      register: installgeneral
 

{
  "changed": true,
  "stdout": "Starting galaxy collection install process\nProcess install dependency map\nto see the full traceback, use -vvv",
  "stderr": "\u001b[1;35m[WARNING]: Skipping Galaxy server https://galaxy.ansible.com/api/. Got an\u001b[0m\n\u001b[1;35munexpected error when getting available versions of collection\u001b[0m\n\u001b[1;35mcommunity.general: '/api/v3/plugin/ansible/content/published/collections/index/\u001b[0m\n\u001b[1;35mcommunity/general/versions/'\u001b[0m\n\u001b[0;31mERROR! Unexpected Exception, this is probably a bug: '/api/v3/plugin/ansible/content/published/collections/index/community/general/versions/'\u001b[0m",
  "rc": 250,
  "cmd": "ansible-galaxy collection install community.general",
  "start": "2024-01-28 08:57:19.687034",
  "end": "2024-01-28 08:57:20.569548",
  "delta": "0:00:00.882514",
  "msg": "non-zero return code",
  "invocation": {
    "module_args": {
      "_raw_params": "ansible-galaxy collection install community.general",
      "_uses_shell": true,
      "warn": false,
      "stdin_add_newline": true,
      "strip_empty_ends": true,
      "argv": null,
      "chdir": null,
      "executable": null,
      "creates": null,
      "removes": null,
      "stdin": null
    }
  },
  "stdout_lines": [
    "Starting galaxy collection install process",
    "Process install dependency map",
    "to see the full traceback, use -vvv"
  ],
  "stderr_lines": [
    "\u001b[1;35m[WARNING]: Skipping Galaxy server https://galaxy.ansible.com/api/. Got an\u001b[0m",
    "\u001b[1;35munexpected error when getting available versions of collection\u001b[0m",
    "\u001b[1;35mcommunity.general: '/api/v3/plugin/ansible/content/published/collections/index/\u001b[0m",
    "\u001b[1;35mcommunity/general/versions/'\u001b[0m",
    "\u001b[0;31mERROR! Unexpected Exception, this is probably a bug: '/api/v3/plugin/ansible/content/published/collections/index/community/general/versions/'\u001b[0m"
  ],
  "_ansible_no_log": false,
  "_ansible_delegated_vars": {
    "ansible_host": "localhost",
    "ansible_port": null,
    "ansible_user": "olamuser",
    "ansible_connection": "local"
  }
}

作为解决方案,我尝试使用

 --no-cache
安装,它成功运行,如下所示,但
xml
模块仍然错误:

---
- name: Get DB details from tomcat xml
  hosts: your_target_host
  environment:
    ANSIBLE_COLLECTIONS_PATHS: "/runner/requirements_collections"
  tasks:
    - name: Install general
      shell: ansible-galaxy collection install community.general --no-cache
      become_user: root
      delegate_to: localhost
      register: installgeneral
      
    - name: Get DB details from tomcat xml
      include_tasks: "{{ playbook_dir }}/extractfromxml.yml"
      vars: 
        xmlpath_rec: "{{ xmlpath_rec }}"
        DBname: "{{ DBname }}"
    
    - debug:
        msg: "INSTALLGENERAL: {{ installgeneral }}"
    

cat extractfromxml.yml

---

- name: Extract DB details from XML
  community.general.xml:
    path: "{{ xmlpath_rec }}"
    xpath: "/Server/Service/GlobalNamingResources/Resource[@name='{{ DBname }}']"
    content: text
  register: db_details      

输出:

{
  "msg": "INSTALLGENERAL: {'changed': True, 'stdout': \"Starting galaxy collection install process\\nProcess install dependency map\\nStarting collection install process\\nDownloading https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/community-general-8.2.0.tar.gz to /root/.ansible/tmp/ansible-local-125pzia2sj6/tmpgs0_jwew/community-general-8.2.0-xv57fqkm\\nInstalling 'community.general:8.2.0' to '/runner/requirements_collections/ansible_collections/community/general'\\ncommunity.general:8.2.0 was installed successfully\", 'stderr': '', 'rc': 0, 'cmd': 'ansible-galaxy collection install community.general --no-cache', 'start': '2024-01-28 09:19:41.413594', 'end': '2024-01-28 09:19:45.208997', 'delta': '0:00:03.795403', 'msg': '', 'stdout_lines': ['Starting galaxy collection install process', 'Process install dependency map', 'Starting collection install process', 'Downloading https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/community-general-8.2.0.tar.gz to /root/.ansible/tmp/ansible-local-125pzia2sj6/tmpgs0_jwew/community-general-8.2.0-xv57fqkm', \"Installing 'community.general:8.2.0' to '/runner/requirements_collections/ansible_collections/community/general'\", 'community.general:8.2.0 was installed successfully'], 'stderr_lines': [], 'failed': False}",
  "_ansible_verbose_always": true,
  "_ansible_no_log": false,
  "changed": false
}

TASK [Get DB details from tomcat xml] ******************************************
fatal: [remotehost]: FAILED! => {"reason": "couldn't resolve module/action 'community.general.xml'. This often indicates a misspelling, missing collection, or incorrect module path.\n\nThe error appears to be in '/runner/project/tomcat_templates/extractfromxml.yml': line 3, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Extract DB details from XML\n  ^ here\n"}

我尝试列出并检查

community.general
是否已正确安装,如下所示:

- name: LIST general
  shell: ansible-galaxy collection list -p /runner/requirements_collections
  become_user: root
  delegate_to: localhost
  register: listgeneral

- debug:
    msg: "LISTGENERAL: {{ listgeneral }}"

输出:

{
  "msg": "LISTGENERAL: {'changed': True, 'stdout': '\\n# /runner/requirements_collections/ansible_collections\\nCollection        Version\\n----------------- -------\\nansible.posix     1.5.4  \\ncommunity.general 8.2.0  ', 'stderr': '', 'rc': 0, 'cmd': 'ansible-galaxy collection list -p /runner/requirements_collections', 'start': '2024-01-28 09:56:18.101264', 'end': '2024-01-28 09:56:18.484268', 'delta': '0:00:00.383004', 'msg': '', 'stdout_lines': ['', '# /runner/requirements_collections/ansible_collections', 'Collection        Version', '----------------- -------', 'ansible.posix     1.5.4  ', 'community.general 8.2.0  '], 'stderr_lines': [], 'failed': False}",
  "_ansible_verbose_always": true,
  "_ansible_no_log": false,
  "changed": false
}

您能否建议为什么我安装后仍无法使用 xml 模块?

示例 tomcat server.xml:

cat /web/bea_apps/uat/Tomcat_Home_v9.0.56/TomcatNode01/conf/server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8048" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener" />
  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />

  <GlobalNamingResources>
          <Resource name="UserDatabase" auth="Container"
              type="org.apache.catalina.UserDatabase"
              description="User database that can be updated and saved"
              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
              pathname="conf/tomcat-users.xml" />

    <Resource auth="Container"
        driverClassName="oracle.jdbc.OracleDriver"
        global="dsCanweb"
        name="dsCanweb"
        password="P5jYL3yhwMF_Ep8P"
        username="CAN_WEB_USER"
        url="jdbc:oracle:thin:@MYHOST36db06v.mybc.com:1521:DB01"
        type="javax.sql.DataSource"
        factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
        initialSize="15" maxTotal="150" maxActive="100" maxWaitMillis="10000" minIdle="15"
        accessToUnderlyingConnectionAllowed="true"
        minEvictableIdleTimeMillis="90000"
        logAbandoned="true" removeAbandoned="true" removeAbandonedTimeout="7200"
        removeAbandonedOnBorrow="true" removeAbandonedOnMaintenance="true"
        jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer;SlowQueryReport(threshold=600000,logFailed=true)"
        testWhileIdle="true"
        validationQuery="select 1 from dual"
        validationInterval="30000"
        testOnBorrow="true" />

    <Resource auth="Container"
        driverClassName="oracle.jdbc.OracleDriver"
        global="canwebds"
        name="canwebds"
        password="RMbbgwfxt2Os_2024"
        username="CANADA_WEB_USER"
        url="jdbc:oracle:thin:@MYHOST36DB06V.mybc.com:1521/oltt206"
        type="javax.sql.DataSource"
        factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
        initialSize="15" maxTotal="150" maxActive="100" maxWaitMillis="10000" minIdle="15"
        accessToUnderlyingConnectionAllowed="true"
        minEvictableIdleTimeMillis="90000"
        logAbandoned="true" removeAbandoned="true" removeAbandonedTimeout="7200"
        removeAbandonedOnBorrow="true" removeAbandonedOnMaintenance="true"
        jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer;org.apache.tomcat.jdbc.pool.interceptor.ResetAbandonedTimer;SlowQueryReport(threshold=600000,logFailed=true)"
        testOnBorrow="true" />

</GlobalNamingResources>

  <Service name="Catalina">

    <Connector port="12408" address="uswl1212myb01.MYHOST35as28v.mybc.com" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="12409" />

<Connector port="12404" address="uswl1212myb01.MYHOST35as28v.mybc.com" protocol="AJP/1.3" redirectPort="12409" requiredSecret="QmtmM3hWcEVzUW5VTDNLdQo=" />

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker8">

      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Valve className='org.apache.catalina.valves.ErrorReportValve'
                showServerInfo='false' />

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>
  </Service>
</Server>
xml ansible xml-parsing runtime-error ansible-galaxy
1个回答
0
投票

ansible playbook 主机(运行程序)是 OLAM EE 环境(Oracle Linux 自动化管理器)提供的 docker 容器,不属于我的团队。

来自

community.general.xml
文档:

如果您使用

ansible
软件包,您可能已经安装了此集合。它不包含在
ansible-core
中。

所以基本上主要问题是您的执行环境似乎不正确,因为它可能只安装了

ansible-core
而不是
ansible

作为解决方案,我尝试使用

--no-cache
安装,它成功运行,如下所示,但 xml 模块仍然错误

如果您的 EE 是 Docker 容器,那么您很可能每次都运行一个新实例。我怀疑 Ansible 是否能够动态加载集合(例如,当剧本已经运行时)。

我看到的唯一正确的解决方案是正确准备执行环境 - 要么安装整个

ansible
包,要么单独安装所有必需的集合。

© www.soinside.com 2019 - 2024. All rights reserved.