gpt4 book ai didi

ansible - 是否可以在 YAML 中编写 Ansible 主机/ list 文件?

转载 作者:行者123 更新时间:2023-12-03 08:48:14 26 4
gpt4 key购买 nike

在最佳实践页面中,有一个使用 hosts.yml 的示例。对于主机文件:

YAML-based hosts file

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

YAML 中 list 文件的语法是什么?

最佳答案

是的。

已经deprecated在 2012 年的 0.6 版和 reintroduced 中在 2016 年首次包含在 2.1 版中的提交中。

example file GitHub 上包含指南和示例:

  • 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: 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: 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:

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:

关于ansible - 是否可以在 YAML 中编写 Ansible 主机/ list 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41094864/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com