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

查看:28
本文介绍了是否可以在 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 版中弃用在 2016 年首次包含在 2.1 版中的提交中重新引入.

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:

  • 评论以#"字符开头
  • 忽略空行
  • 假定顶级条目是组
  • 必须在组的主机中指定主机:并且它们必须是键(:终止)
  • 组可以有子项、主机和变量键
  • 假设在 hosts 下定义的任何内容都是 var
  • 您可以输入主机名或 IP 地址
  • 一个主机名/IP 可以是多个组的成员

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:您可以使用范围创建主机并将子组和变量添加到组中.子组可以定义您通常添加到组中的任何内容

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天全站免登陆