xml - Ansible Xml 模块 - 从寄存器中获取带有命名空间的 xml 值
问题描述
有一个 pom.xml 文件,我使用以下任务提取项目名称
- name: Loading project variables from the parent Maven pom.xml
xml:
path: "/some/path/pom.xml"
namespaces:
ns: "http://maven.apache.org/POM/4.0.0"
xpath: "/ns:project/ns:name"
content: text
register: project_name_reg
- name: "Set project name"
set_fact:
project_name: "{{ project_name_reg.matches[0] }}"
它有效,现在project_name
包含:
"project_name": {
"{http://maven.apache.org/POM/4.0.0}name": "My Project Parent"
}
如何My Project Parent
通过这个带有命名空间的复杂{http://maven.apache.org/POM/4.0.0}name
名称提取真正的价值?这是一个简单的字典,但我所有的尝试都失败了。
解决方案
你根本不在乎那把钥匙。你可以这样做:
- name: "Set project name"
set_fact:
project_name: "{{ project_name_reg.matches[0].values()|first }}"
推荐阅读
- android - 如何使用 sparkjava 框架 webserver 和 Android 设备发送大文件?
- javascript - 为什么我在使用 Vue/Nuxt 时会遇到 fontawesome 星星的间距问题?
- c++ - 为什么使用implicit_cast
(int) 而不是 static_cast (整数)? - python - Collatz 在 Python 中的假设检验
- bash - 分组命令的意外标记附近的bash语法错误
- mysql - 如何将 MySQL Workbench 连接到在 VPC 中运行的 Amazon RDS
- sql - 在 Hive SQL 中检索多个链表
- stripe-payments - 带有多个 webhook 的条带
- postgresql - SOCI/Postgresql 中的批量插入顺序
- javascript - 如何使用 JavaScript/TypeScript 将字符串转换为数组