首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ansible regex tomcat版本

Ansible regex tomcat版本
EN

Stack Overflow用户
提问于 2019-06-28 13:33:11
回答 2查看 160关注 0票数 0

我已经为一个问题挣扎了几个小时,我希望在任务文件中只对一个特定版本的tomcat执行一个操作,例如:

代码语言:javascript
复制
- 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,那么它应该是匹配的模式,但我得到了一个奇怪的错误,我看不出我遗漏了什么引号

代码语言:javascript
复制
 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"}

谢谢你的帮助。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-28 14:02:26

应如下所示:

代码语言:javascript
复制
---
- hosts: localhost
  tasks:
    - name: plat
      debug:
        msg: "Success"
      when: '"{{ tomcat_ver }}" is match("^[8-9]")'

单引号在开头和结尾

票数 0
EN

Stack Overflow用户

发布于 2019-06-28 14:04:09

使用版本比较测试

代码语言:javascript
复制
when: tomcat_ver is version('8', '==') or
      tomcat_ver is version('9', '==')

(未测试)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56807919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档