簡體   English   中英

使用時的Ansible劇本

[英]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返回一個表示可用內存的num(一個整數),我想在何時決定是否執行重啟操作時使用。 但每次我運行該劇本時,它都會跳過重啟操作。 請先幫我一下,謝謝。

shell模塊的文檔提供了返回值的結構,關鍵是它返回的數據結構(dict)除其他外還包含shell命令的“標准輸出”(輸出)。 在返回的字典的stdout屬性中找到該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 < 3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM