Ansible:在插值变量值时,如何将仅考虑一个变量作为强制要求?
创始人
2024-11-07 01:00:40
0

可以使用“必需”属性来使某个变量成为强制要求,并在该变量未定义时引发错误。

以下是一个示例,在其中定义了一个强制要求变量“my_var”:

- name: Example playbook
  hosts: localhost
  vars:
    some_var: 'value1'
    my_var: '{{ my_var | mandatory }}'

  tasks:
    - name: Example task
      debug:
        msg: "The value of some_var is {{ some_var }}, and the value of my_var is {{ my_var }}"

在上面的示例中,如果你在调用 playbook 时不定义 “my_var”,则 playbook 将在插值变量时引发错误,并输出以下错误消息:

TASK [Example Task] *************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'my_var' is undefined\n\nThe error appears to have been in '/path/to/playbook.yml': line 13, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n    - name: Example Task\n      ^ here\n"}

相关内容

热门资讯

教你透视!wepoker正确养... 教你透视!wepoker正确养号方法,微乐自建房辅助工具别人怎么看,指南教程(有挂辅助)-哔哩哔哩1...
曝光透视!德州hhpoker脚... 曝光透视!德州hhpoker脚本,微乐自建房脚本下载,总结教程(有挂方针)-哔哩哔哩1、用户打开应用...
必备透视!aapoker透视方... 必备透视!aapoker透视方法,微乐自建房免费黑科技有哪些,项目教程(新版有挂)-哔哩哔哩1、该软...
专业透视!wepoker有人用... 专业透视!wepoker有人用过吗,微乐游戏竞技团辅助,法门教程(新版有挂)-哔哩哔哩1、任何wep...
科普透视!hhpoker是内部... 科普透视!hhpoker是内部控制吗,微乐小程序多功能修改器,练习教程(有挂解惑)-哔哩哔哩所有人都...
关于透视!德州机器人代打脚本,... 关于透视!德州机器人代打脚本,微乐广西小程序开挂,秘籍教程(真是有挂)-哔哩哔哩1、起透看视 德州机...
科普透视!hhpoker辅助靠... 科普透视!hhpoker辅助靠谱吗,微乐广西麻辣,手册教程(有挂方法)-哔哩哔哩1、hhpoker辅...
分享透视!德州私人局怎么透视,... 分享透视!德州私人局怎么透视,手机微乐小程序破解器如何使用,手段教程(揭秘有挂)-哔哩哔哩1、金币登...
科普透视!pokemmo辅助工... 科普透视!pokemmo辅助工具,小程序微乐辅助器2.0,指南书教程(有挂方法)-哔哩哔哩1、每一步...
专业透视!wepoker有没有... 专业透视!wepoker有没有辅助,微乐自建房脚本免费下载,法门教程(真的有挂)-哔哩哔哩1、许多玩...