簡體   English   中英

Ansible正則表達式tomcat版本

[英]Ansible regex tomcat version

我現在正在為一個問題苦苦掙扎幾個小時,我想在task文件中僅對特定版本的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]")'

開頭和結尾的單引號

使用版本比較測試

when: tomcat_ver is version('8', '==') or
      tomcat_ver is version('9', '==')

(未測試)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM