我正在使用最新版本的 Ansible,并且尝试使用默认变量 inused role-oneon host one、 in role-two、used on host two,但我无法让它工作。
我在文档或 StackOverflow 上发现的任何内容都没有真正帮助。我不确定我做错了什么。理想情况下,我希望设置变量的值一次,并能够在我的剧本中的任何主机的另一个角色中使用它。
我已将其分解如下。
在我的清单中,我有一个名为 的主机组[test],其中有两个别名为one和 的主机two。
[test]
one ansible_host=10.0.1.10 ansible_connection=ssh ansible_user=centos ansible_ssh_private_key_file=<path_to_key>
two ansible_host=10.0.1.20 ansible_connection=ssh ansible_user=centos ansible_ssh_private_key_file=<path_to_key>
Run Code Online (Sandbox Code Playgroud)
我有一个剧本,其中包含每个主机的剧本,并且我提供了host和host 的hosts:值。"{{ host_group }}[0]"one"{{ host_group }}[1]"two
主机的戏剧one使用名为 的角色role-one,主机的戏剧two使用名为 的角色role-two。
[test]
one ansible_host=10.0.1.10 ansible_connection=ssh ansible_user=centos ansible_ssh_private_key_file=<path_to_key>
two ansible_host=10.0.1.20 ansible_connection=ssh ansible_user=centos ansible_ssh_private_key_file=<path_to_key>
Run Code Online (Sandbox Code Playgroud)
在role-one我设置了一个变量 …
ansible ×1