如何将变量值传递给Ansible中的角色

huangapple go评论63阅读模式
英文:

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

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

huangapple
  • 本文由 发表于 2023年2月13日 23:01:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75437605.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定