是否可以在YAML中写入Ansible主机/清单文件? [英] Is it possible to write Ansible hosts/inventory files in YAML?

查看:121
本文介绍了是否可以在YAML中写入Ansible主机/清单文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在最佳做法"页面中,有一个示例,将hosts.yml用于主机文件:

In the best practices page, there is an example that uses hosts.yml for hosts files:

但是,在文档中,我只能找到用于编写主机文件的INI语法.

In the docs, however, I can only find the INI syntax for writing hosts files.

YAML中库存文件的语法是什么?

What is the syntax for the inventory files in YAML?

推荐答案

是.

在2012年的0.6版中,已弃用

It's been deprecated in version 0.6 in 2012 and reintroduced in a commit first included in version 2.1 in 2016.

GitHub上的示例文件包含准则和示例:

The example file on GitHub contains the guidelines and examples:

  • 注释以#"字符开头
  • 空白行将被忽略
  • 假定顶级条目为组
  • 必须在组的主机中指定主机:它们必须是密钥(:终止)
  • 组可以具有子代,主机和vars键
  • 在主机下定义的任何内容均假定为var
  • 您可以输入主机名或IP地址
  • 主机名/IP可以是多个组的成员
  • Comments begin with the '#' character
  • Blank lines are ignored
  • Top level entries are assumed to be groups
  • Hosts must be specified in a group's hosts: and they must be a key (: terminated)
  • groups can have children, hosts and vars keys
  • Anything defined under a hosts is assumed to be a var
  • You can enter hostnames or ip addresses
  • A hostname/ip can be a member of multiple groups

Ex 1:未分组的主机,放在未分组"组中

Ex 1: Ungrouped hosts, put in 'ungrouped' group

ungrouped:
  hosts:
      green.example.com:
          ansible_ssh_host: 191.168.100.32
      blue.example.com:
      192.168.100.1:
      192.168.100.10:

Ex 2:属于"webservers"组的主机的集合

Ex 2: A collection of hosts belonging to the 'webservers' group

webservers:
  hosts:
      alpha.example.org:
      beta.example.org:
      192.168.1.100:
      192.168.1.110:

示例3:您可以使用范围创建主机,并将子组和var添加到组中. 子组可以定义通常添加到组中的任何内容

Ex 3: You can create hosts using ranges and add children groups and vars to a group. The child group can define anything you would normally add to a group

testing:
  hosts:
      www[001:006].example.com:
  vars:
      testing1: value1
  children:
      webservers:
          hosts:
              beta.example.org:

这篇关于是否可以在YAML中写入Ansible主机/清单文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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