Ansible playbook when usage

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Ansible playbook when usage


- 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 returns a num(an integer) that represents free memory,I want to use when to decide whether execute restart action. but every time I run the playbook.it will skip restart action. please give me a hand, thanks in advance.




1 Answer
1



The shell documentation modules provides the structure of the return values, stdout contains the output of the executed command (and so is stdout_lines).


stdout


stdout_lines



I added also a filter to convert the value to an integer.


- 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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Makefile test if variable is not empty