YAML:等号(=)可以用于字典吗? [英] YAML: When an equals sign (=) can be used for dictionaries?

查看:393
本文介绍了YAML:等号(=)可以用于字典吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是在应该用YAML编写的有趣的剧本中阅读key1=value1 key2=value2风格的词典.另一方面,我没有找到任何关于这种格式的文档,并且似乎在某些情况下它不适用于我.确切的规格是什么?在哪里可以找到它?

I read key1=value1 key2=value2 style dictionaries all the time in ansible playbooks that are supposed to be written in YAML. On the other hand I didn't find any documentation for this format and there seem to be cases where it doesn't work for me. What is the exact specification and where can I find it?

推荐答案

在Ansible中,key=value通常不用于字典.

In Ansible key=value is not used for dicts in general.

将参数传递给动作/模块是另一种语法,例如:

It is an alternative syntax to pass parameters to actions/modules, like:

- name: restart apache
  service: name=apache state=restarted

此处将namestate参数传递给service模块.

Here you pass name and state parameters to service module.

从YAML角度来看,name=apache state=restarted是一个字符串. Ansible在引擎盖下做了一些魔术来拆分它.但是使用复杂的参数会变得不可靠且麻烦,因此我始终使用本机YAML语法:

From YAML perspective name=apache state=restarted is a string. There's some magic done under the hood by Ansible to split it. But it become unreliable and cumbersome with complex arguments, so I always use native YAML syntax:

- name: restart apache
  service:
    name: apache
    state: restarted

key=value仅适用于模块/动作参数,您无法定义这样的字典:

And this key=value works only for modules/actions parameters, you can't define dictionaries like this:

vars:
  # this will give you a string, not dict
  mydict: key1=value1 key2=value 

这篇关于YAML:等号(=)可以用于字典吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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