可以使用when关键字来判断变量是否为空,如果为空则不执行task,例如:

- name: Do something only if variable is not empty
  debug:
    msg: "Variable is not empty"
  when: my_variable is defined and my_variable != ''

在上面的例子中,当my_variable已定义且不为空时,才执行debug任务。如果变量未定义或为空,则不执行该任务。

在ansible中对变量值进行判断如果变量值为空不执行task请举例

原文地址: http://www.cveoy.top/t/topic/KTK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录