Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Shell 在Ansible剧本中使用sed命令_Shell_Sed_Ansible_Ansible 2.x - Fatal编程技术网

Shell 在Ansible剧本中使用sed命令

Shell 在Ansible剧本中使用sed命令,shell,sed,ansible,ansible-2.x,Shell,Sed,Ansible,Ansible 2.x,我想使用下面的命令从我的pom.xml返回版本,但它不起作用 - name: ensure apache is at the latest version shell: "echo cat \/\/*[local-name()='project']\/*[local-name()='version'] | xmllint --shell pom.xml | sed '\/^\/ >/d' | sed 's/<[^>]*.//g'" register: Artif

我想使用下面的命令从我的
pom.xml
返回版本,但它不起作用

- name: ensure apache is at the latest version
    shell: "echo cat \/\/*[local-name()='project']\/*[local-name()='version'] | xmllint --shell pom.xml | sed '\/^\/ >/d' | sed 's/<[^>]*.//g'"
    register: ArtifactId
- debug: var=ArtifactId.stdout_lines
-name:确保apache是最新版本
shell:“echo cat\/\/*[local-name()='project']\/*[local-name()='version']| xmllint--shell pom.xml | sed'\/^\/>/d'| sed's/]*.//g'”
寄存器:ArtifactId
-调试:var=ArtifactId.stdout\u行

有人能帮忙吗?

这更多的是一个基本的shell问题,而不是一个可解决的问题。即使没有ansible,该命令行也会生成错误:

$ echo cat \/\/*[local-name()='project']\/*[local-name()='version'] | xmllint --shell pom.xml | sed '\/^\/ >/d' | sed 's/<[^>]*.//g'
bash: syntax error near unexpected token `('
使用
折叠标量运算符可以避免一定程度的引用,从而使命令更易于管理。它还允许您将其格式化为更具可读性

考虑到以下输入:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <version>4.0.0</version>
</project>

尽管如此,您可能需要考虑使用某种类型的XPath模块来代替ANDILE。虽然我自己没有尝试过,但似乎最近有一些活动。

这更多的是一个基本的shell问题,而不是一个可解决的问题。即使没有ansible,该命令行也会生成错误:

$ echo cat \/\/*[local-name()='project']\/*[local-name()='version'] | xmllint --shell pom.xml | sed '\/^\/ >/d' | sed 's/<[^>]*.//g'
bash: syntax error near unexpected token `('
使用
折叠标量运算符可以避免一定程度的引用,从而使命令更易于管理。它还允许您将其格式化为更具可读性

考虑到以下输入:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <version>4.0.0</version>
</project>

尽管如此,您可能需要考虑使用某种类型的XPath模块来代替ANDILE。似乎有最近的活动,尽管我自己没有尝试过。

您遇到了什么错误?您遇到了什么错误?我在debian中进行了测试,但它打印了两行不同的结果:
ok:[localhost]=>{“artifactId.stdout_行”:[“----”,“0.1.0-SNAPSHOT”]}
听起来您现在可能只需要修复XPath表达式。如果您想用一个可复制的示例更新您的问题(一个可运行的剧本和相应的
pom.xml
,它会导致所描述的行为),我很乐意仔细查看。我已经在debian中对其进行了测试,但它打印了两行不同的结果:
ok:[localhost]=>{“artifactId.stdout\u行”:[“----”,“0.1.0-SNAPSHOT”]}
听起来您现在可能只需要修复XPath表达式。如果您想用一个可复制的示例(一个可运行的剧本和相应的导致所描述行为的
pom.xml
)更新您的问题,我很乐意仔细查看。