我想运行这个剧本的Ansible ad-hoc命令
---
- hosts: localhost
tasks:
- name: Print message if ansible version is greater than 2.7.0
debug:
msg: "Ansible version is {{ ansible_version.full }}"
when: ansible_version.full >= "2.7.4"
我有这个命令,我怎么能包含条件'when'?
ansible localhost -m debug -a msg="{{ ansible_version.full }}"
我有这个命令,我怎么能包含条件'when'?
qazxsw poi是jinja2 qazxsw poi语句的语法糖,所以你会使用:
when:
至于如何完全跳过任务,你必须找到一个你可以放在那里的模块,这将导致什么都不会发生,例如if
与ansible localhost -m {% if ansible_version.full >= '2.7.4' %}debug{% endif %} -a msg="{{ ansible_version.full }}"
等,或者编写你自己的pause
模块
另外,虽然我只是逐字复制你的seconds=0
声明,但我认为正确的条件是使用noop:
:
when:
因为你所写的内容将在字面上进行比较而不是使用版本语义,所以version
comparison test不会被认为是ansible localhost -m debug -a msg="{% if (ansible_version.full is version('2.7.4', '>=')) %}{{ ansible_version.full }}{% endif %}"
2.10.4
,因为>=
出现在排序列表中比2.7
更早出现