英文:
How to pass variable values to roles in Ansible
问题
I want to pass the values to roles from the input which I'm getting from vars_prompt
. Kindly advise is it possible or not.
-name: 创建主题
hosts: all
vars_prompt:
- name: environment
prompt: "输入环境"
private: no
roles:
- "{{ environment }}"
When I run the playbook, I'm getting an error. Error! environment is undefined
Kindly advise how to pass the value to roles.
Want to pass the values to roles.
英文:
I want to pass the values to roles from the input which im getting from vars_prompt
.
Kindly advise is it possible or not.
-name: Topic creation
hosts: all
vars_prompt:
- name: environment
prompt: "Enter the environment"
private: no
roles:
- "{{ environmet }}"
When i run the playbook getting an error.
Error! environment is undefined
Kindly advise how to pass the value to roles.
Want to pass the values to roles.
答案1
得分: 0
如果我理解正确,您观察到的错误通常是由于编译时和运行时变量初始化差异引起的。
根据错误消息
roles:
- "{{ environment }}"
将在编译时解析,而在运行时提示环境之前。
vars_prompt:
- name: environment
prompt: "Enter the environment"
private: no
您还可以查看有关以下内容的进一步文档
-
以任务的方式动态加载和执行指定的角色。
这意味着您需要更改引用角色或为其提供名称的方式。参见
类似的问答
英文:
If I understand that corerct the error you are observing is usually because of the variable initialization difference between compile time and runtime.
According the error message
roles:
- "{{ environment }}"
would be resolved during compile time and before the prompting for the environment during runtime.
vars_prompt:
- name: environment
prompt: "Enter the environment"
private: no
You may also have a look into further documentation about
-
include_role
module – Load and execute a role> Dynamically loads and executes a specified role as a task.
This means you would need to change the way you are referencing the role or providing the name for it. See a
Similar Q&A
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论