该角色尝试从树莓派计算机(仅在此情况下为host1)获取cpu温度,检查docker容器boinc_universeathome是否正在运行,然后检查该容器是否正在运行,并且cpu temp> highThresholdTrigger,则应暂停该容器。
如果我在角色中没有when子句的情况下运行此命令,则正确地它总是会暂停容器。
当when子句始终存在时,为什么它不起作用?我希望使用when子句,仅应在满足条件时暂停容器。但是这个条件从来没有得到满足。
大概这是因为我编写when子句的方式有问题,但是我不知道这是什么错误?
(我知道我在这里使用shell而不是docker模块)
我的房东:
[monitorrpihosts]
host1
[monitorrpihosts:vars]
ansible_connection=ssh
ansible_ssh_user=someusername
highThresholdTrigger=70
highThresholdReset=40
Run Code Online (Sandbox Code Playgroud)
我的剧本:
---
- name: Monitor rpi
hosts: monitorrpihosts
become: yes
become_user: root
become_method: sudo
roles:
- monitorrpi
Run Code Online (Sandbox Code Playgroud)
我的角色:
---
- 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 …Run Code Online (Sandbox Code Playgroud) ansible ×1