我正在编写一个剧本,该剧本仅应在软件的新软件包版本可用时运行。两个版本号都是我用“set_fact”设置的自定义事实
Ansible 让你比较版本号,所以我这样尝试:
- name: compare versions
debug:
msg: "The version {{ new_version }} is newer than the old version {{ old_version }}"
when: "{{ new_version is version('{{ old_version }}', '>', strict=True }}"
Run Code Online (Sandbox Code Playgroud)
Ansible 抛出版本号无效的错误。当我将“old_version”设置为固定版本号时,它会按预期工作。是否可以用“版本”来比较两个事实?我已经尝试过使用双引号等不同的方法,这会导致 ansible 中的语法错误。
有任何想法吗?
谢谢
{{可以在条件中使用 Jinja 分隔符。在某种when:情况下,您不需要这些分隔符来进行插值。
下面的例子有效:
vars:
new_version: 14
old_version: 12
tasks:
- debug:
msg: 'The version {{ new_version }} is newer than the old version {{ old_version }}'
when: "new_version is version(old_version, '>')"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2564 次 |
| 最近记录: |