首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >适用于virt commnd状态检查的行动手册

适用于virt commnd状态检查的行动手册
EN

Stack Overflow用户
提问于 2021-03-26 16:48:05
回答 2查看 148关注 0票数 1

我使用下面的实战手册等待vm状态为running,并在vm运行时执行下一步任务。

代码语言:javascript
复制
---
- hosts: localhost
  tasks:

          - name: wait for the vm to shut down
            virt:
               command: status
               name: myCentosVM
            register: vmstatus
            until: vmstatus.status == 'running'
            retries: 1500
            delay: 10

但是我看到了这样的错误

代码语言:javascript
复制
the conditional check 'vmstatus.status == 'running'' failed. The error was: error while evaluating conditional (vmstatus.status == 'running'): 'dict object' has no attribute 'status'"

任何帮助都是非常感谢的。

EN

回答 2

Stack Overflow用户

发布于 2021-03-26 17:50:50

代码语言:javascript
复制
the conditional check 'vmstatus.status == 'running'' failed. The error was: error while evaluating conditional (vmstatus.status == 'running'): 'dict object' has no attribute 'status'

你的错误是不言而喻的。变量Vmstatus不包含任何像status这样的属性。所以,你不能使用vmstatus.status。第一次运行

代码语言:javascript
复制
- name: wait for the vm to shut down
  virt:
    command: status
    name: myCentosVM
  register: vmstatus
- debug: var=vmstatus 

它将打印输出包含的属性列表,因此您可以应用检查条件。

如果问题仍然存在,请在此处分享调试输出。

票数 0
EN

Stack Overflow用户

发布于 2021-03-27 02:16:08

这是因为直到命令成功(或给出非零返回代码),才会在重试过程中定义字典键status

要处理这些情况,您可以使用Jinja的内置测试defined

代码语言:javascript
复制
- hosts: localhost
  tasks:
    - virt:
        command: status
        name: myCentosVM
      register: vm
      until: vm.status is defined and vm.status == 'running'
      retries: 1500
      delay: 10
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66813632

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档