错误! “失败"不是Play的有效属性 [英] ERROR! 'fail' is not a valid attribute for a Play

查看:271
本文介绍了错误! “失败"不是Play的有效属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Ansible的新手.以下是我要播放的剧本的小片段,但遇到错误"ERROR!'fail'不是播放的有效属性"

I'm new to Ansible. Below is the small snippet of the playbook which I am trying to play but facing the error "ERROR! 'fail' is not a valid attribute for a Play"

---
   - vars_prompt:
        - name: "var1"
          prompt: "Please pass variable"
          private: no

   - fail: msg="var1 is not passed or blank"
     when: var1 is undefined or ( var1 is defined and storeid == "" )

我尝试了在stackoverflow上找到多个选项,但没有成功.

I have tried multiple options found on stackoverflow but no success.

推荐答案

必须在任务级别使用fail指令.

The fail directive has to be used at the task level.

这意味着要获得想要的效果,您必须做类似的事情

This means that to get your desired effect, you would have to do something like

---
   vars_prompt:
      - name: "var1"
        prompt: "Please pass variable"
        private: no

   tasks:
     - fail: msg="var1 is not passed or blank"
       when: var1 is undefined or ( var1 is defined and storeid == "" )

您只需将其余任务放在该声明之后. "ERROR!'fail'不是播放的有效属性"消息是因为您当前在嵌套级别上将其声明为Ansible期望播放.

And you would simply place the rest of your tasks after that declaration. The "ERROR! 'fail' is not a valid attribute for a Play" message is because you're currently declaring it at a nesting level that Ansible is expecting to be a play.

这篇关于错误! “失败"不是Play的有效属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆