linux - 当条件处于ansible状态时

标签 linux automation ansible

我编写了以下剧本,它工作正常,但是当我对角色做同样的事情时,当失败模块的情况发生困惑时。无论定义的值如何,当我在失败模块中给出 > 时,它会跳过,而当给出 < 时,它会失败。 请不要介意语法和“-”,它在这里很困惑。

- hosts: localhost
  vars: 
    vmcpu_list:
      - vmcpu: 2
      - vmcpu: 1
      - vmcpu: 1
    vcpu_value: 0 

  tasks:
    - set_fact: 
          vcpu_value: "{{ vcpu_value }} + vmcpu_list[{{item}}].vmcpu"
      with_sequence: start=0 end="{{ vmcpu_list | length -1 }}" 
    - debug:
           var: "{{ vcpu_value }}"
    - fail: 
          msg: " provided vcpu are more"
      when: vcpu_value|int > 5

注意:抱歉,之前我在上面给出了 vcpu_value|int > 5,但它应该是 vcpu_value|int > 3

最佳答案

 - fail: 
          msg: " provided vcpu are more"
      when: vcpu_value|int > 5

您已设置 vcpu_value: 0 条件评估 vcpu_value < 5 与您的条件不符 ==> ansible 将跳过该任务

   - fail: 
              msg: " provided vcpu are more"
          when: vcpu_value|int < 5

您已设置 vcpu_value: 0 条件评估 vcpu_value < 5 OK ==> ansible 将执行任务

没有问题,你的代码工作正常,没有奇怪的行为^^

关于linux - 当条件处于ansible状态时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55278861/

相关文章:

shell - ansible 命令/shell 模块似乎没有评估和选择参数

linux - 编译ffprobe linux库

c - 从用户空间获取打开文件的引用计数(inode->i_count)

powershell - 自动安装 .msi

linux - 如何使用ansible在后台运行kafka代理启动脚本

json - 用于展平对象数组的 JMESPath 表达式,每个对象都有嵌套的对象数组

linux - 侏儒图标包

linux - 内核日志 "file descriptor"用于选择吗?

java - 在 selenium 的每一行中替换 thread.sleep(9000)

mysql - mysql中的自动运行查询