可以使用 ansible 变量在剧本中声明主机吗? [英] Can ansible variables be used to declare hosts in a playbook?
本文介绍了可以使用 ansible 变量在剧本中声明主机吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个格式如下的剧本:
I have a playbook in the format below:
---
- hosts: myIP
tasks:
- name: Install a yum package in Ansible example
yum:
name: ThePackageIWantToInstall
state: present
其中 myIP
和 ThePackageIWantToInstall
是变量.
where myIP
and ThePackageIWantToInstall
are variables.
当作业模板运行时,我希望额外变量弹出窗口中的用户能够使用:
When the job template runs, I would like the user in the extra variables popup to be able to go with:
myIP = 192.168.1.1
ThePackageIWantToInstall = nano
由于文档没有提供通过作业模板提供变量的示例,这可能吗?
As the documentation doesn't provide an example of supplying a variable via a job template, is this possible?
推荐答案
是.
- name: Do The Thing
hosts: "{{ foo }}"
roles:
- "{{ role }}"
需要胡子和引号.
(我不使用这个,但有人建议修改它,谢谢...)
foo: 值
这篇关于可以使用 ansible 变量在剧本中声明主机吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文