我已经为一个问题挣扎了几个小时,我希望在任务文件中只对一个特定版本的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"}谢谢你的帮助。
发布于 2019-06-28 14:02:26
应如下所示:
---
- hosts: localhost
tasks:
- name: plat
debug:
msg: "Success"
when: '"{{ tomcat_ver }}" is match("^[8-9]")'单引号在开头和结尾
发布于 2019-06-28 14:04:09
https://stackoverflow.com/questions/56807919
复制相似问题