ansible - Ansible 正则表达式 tomcat 版本
问题描述
我已经为一个问题苦苦挣扎了几个小时,我希望在任务文件中只为特定版本的 tomcat 执行操作,例如:
- name: Copy new context.xml(Manager App) for tomcat8 or 9
template:
src: templates/tomcat8-9/manager/context.xml
dest: /usr/share/tomcat/webapps/manager/META-INF/context.xml
owner: tomcat
group: tomcat
when: "{{ tomcat_ver }}" is match("^[8-9]")
如果我的 tomcat_ver 是 9.0.20,那么它应该与模式匹配,但我遇到了一个奇怪的错误,我看不出我在哪里缺少任何报价
fatal: [tomcatbis]: FAILED! => {"reason": "Syntax Error while loading YAML.\n did not find expected key\n\nThe error appears to be in '/projects/ansibles/roles/tomcat/tasks/tomcat-setup-Debian.yml': line 69, column 28, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n group: tomcat\n when: \"{{ tomcat_ver }}\" is match(\"^[8-9]\")\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n"}
谢谢你的帮助。
解决方案
它应该如下所示:
---
- hosts: localhost
tasks:
- name: plat
debug:
msg: "Success"
when: '"{{ tomcat_ver }}" is match("^[8-9]")'
开头和结尾的单引号
推荐阅读
- rxjs - 如何在一个承诺中加载一个包含所有子集合的 firebase-collection?
- python - 使用 python 在网络抓取中获取标签的内容而不获取其子项的内容
- css - 如何创建 1 列始终居中的 3 列 flexbox 容器?
- plugins - ansible受管节点无法查看文件内容
- python - 如何将 SVG 提供给 Flask 网站
- javascript - MongoDB 嵌套组聚合
- typescript - Storybook 不支持 vuetify 的 v-calendar
- c# - 在 Solr 中向 RequestHandler 添加组件字符串(有或没有 SolrNet)
- printing - 如何打印没有白条的 Beamer 演示文稿?
- sql - Pyspark - 如何按主键删除记录?