比较整数值时显示

比较整数值时显示

本文介绍了比较整数值时显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此角色尝试从树莓派计算机(在此情况下仅为host1)获取cpu温度,检查docker容器boinc_universeathome是否正在运行,然后检查该容器是否正在运行,并且cpu temp> highThresholdTrigger,则应暂停该容器.

This role attempts to get cpu temperatures from raspberry pi computers (host1 only in this case), check whether docker container boinc_universeathome is running, and then if the container is running and the cpu temp > highThresholdTrigger then it should pause the container.

如果我在角色中没有when子句的情况下运行此命令,那么正确地它总是会暂停容器.

If i run this without the when clauses in the role, then correctly it always pauses the container.

当when子句出现时,为什么它不起作用?我希望使用when子句,仅应在满足条件时暂停容器.但是条件永远不会满足.

Why does it not work when the when clauses are present ever? i expect that with the when clauses present, it should only pause the container when the condition is met. But the condition is never met.

大概这是因为我编写when子句的方式有问题,但是我不知道这是怎么回事?

Presumably this is because there is something wrong with the way i am writing the when clauses but i dont know what it wrong?

(我知道我在这里使用shell而不是docker模块)

(I know i'm using shell here and not a docker module)

我的主人:

[monitorrpihosts]
host1

[monitorrpihosts:vars]
ansible_connection=ssh
ansible_ssh_user=someusername
highThresholdTrigger=70
highThresholdReset=40

我的剧本:

---
- name: Monitor rpi
  hosts: monitorrpihosts
  become: yes
  become_user: root
  become_method: sudo

  roles:
   - monitorrpi

我的角色:

---
- name: Get current cpu temp
  shell: '/opt/vc/bin/vcgencmd measure_temp | grep ^temp= | cut -d= -f2 | cut -d\. -f1'
  register: cpu_temp

- name: check if boinc is running
  shell: 'docker ps | grep boinc_universeathome | grep -v Paused'
  ignore_errors: True
  register: boinc_running

- name: pause boinc if cpu temp gt highThreshold
  shell: 'docker pause boinc_universeathome'
  when:
    - cpu_temp.stdout_lines|int > highThresholdTrigger|int
    - boinc_running.rc|int == 0

推荐答案

cpu_temp.stdout_lines 是行的列表.尝试使用 cpu_temp.stdout | int .

cpu_temp.stdout_lines is a list of lines. Try with cpu_temp.stdout|int.

这篇关于比较整数值时显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 03:46