首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >合理使用时的攻略

合理使用时的攻略
EN

Stack Overflow用户
提问于 2018-07-31 10:41:13
回答 1查看 121关注 0票数 0
代码语言:javascript
复制
- name: restart dcache if mem low
  hosts: test
  tasks:
  - name: getMem
    shell: /bin/bash /etc/zabbix/shell/MonitorMem.sh
    register: memNum
  - name: restart dcache if mem low
    shell: killall -9 dcache
    when: memNum < 3

MonitorMem.sh返回一个表示空闲内存的num(一个整数),我想用它来决定何时执行重启操作。但每次我运行时,playbook.it都会跳过重新启动操作。请帮我一把,提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-07-31 12:28:10

shell module's文档提供了返回值的结构,关键是它返回一个数据结构(dict),其中包含外壳命令的“标准输出”(输出)。标准输出可以在返回的字典的stdout属性中找到。stdout_lines属性包含相同的内容,但是每一行都是一个单独的数组条目。

我还添加了一个int jinja过滤器来将字符串值转换为整数。

代码语言:javascript
复制
- name: restart dcache if mem low
  hosts: test

  tasks:
  - name: getMem
    shell: /bin/bash /etc/zabbix/shell/MonitorMem.sh
    register: memNum

  - name: restart dcache if mem low
    shell: killall -9 dcache
    when: memNum.stdout|int < 3
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51604725

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档