- 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 < 3MonitorMem.sh返回一个表示空闲内存的num(一个整数),我想用它来决定何时执行重启操作。但每次我运行时,playbook.it都会跳过重新启动操作。请帮我一把,提前谢谢。
发布于 2018-07-31 12:28:10
shell module's文档提供了返回值的结构,关键是它返回一个数据结构(dict),其中包含外壳命令的“标准输出”(输出)。标准输出可以在返回的字典的stdout属性中找到。stdout_lines属性包含相同的内容,但是每一行都是一个单独的数组条目。
我还添加了一个int jinja过滤器来将字符串值转换为整数。
- 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 < 3https://stackoverflow.com/questions/51604725
复制相似问题