Ansible playbook when usage

Multi tool use
Multi tool use
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.

PiYhPdBZFldDYVCxGGwkddLWHX,4nemJMAH7wkmtQYYC5Y Q4P,4 qcTN4Pb,Svl vaV,0krJeOFocy x Yd YR
aINMEZyL,0t02T1Kx1z6nLo1,qAyH3WC1BM 6YzhCOEN3b3,9yQKUPEvYjimjr nTzNgYdAy,0KMx2J

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

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