剧本中的Vars_prompt [英] Vars_prompt in playbooks

查看:89
本文介绍了剧本中的Vars_prompt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的剧本

---
- hosts: alpha
  vars:
  company: vogo
  tasks:
     - name: debugging
       debug:
         msg: "{{ansible_hostname}}"
  vars_prompt:
     - name: "company"
       prompt: "Where do you work"
       private: no

- hosts: webservers
  vars_prompt:
     - name: "fathercompany"
       prompt: "Where your father works"
       private: no
  tasks:
     - name: test
       debug:
         msg: just testing "{{company2}}"

这是我运行剧本时执行流程的步骤,

Here are the steps of execution flow when I run the playbook,

1-提示1(您在哪里工作)

1 - prompt 1 (Where do you work)

2-任务调试

3-提示2(您父亲在哪里工作)

3 - prompt 2 (Where your father works)

4-任务测试

我有一些问题.

首先,当我运行此剧本时,应首先运行调试"任务,然后在提示符下询问公司名称.但是,当我运行此剧本时,首先,它会询问您在哪里工作?".为什么要先提示?我是否错过了应该通过的某种参数?

First, When I run this playbook, the task "debugging" should run first and then the prompt should ask for the company name. But, when I run this playbook, at the very first step, it asks for "Where do you work ?". Why prompt first ? Am I missing some kind of paramater which I should have passed ?

第二,我在这里输入了2条提示,

Second, I have put 2 prompts here,

我想在 webservers 主机块中使用提示值 company .但是当我尝试这样做时却给了我错误.

I want to use the prompt value company, in the webservers host block. But it gives me error when I try to do that.

我不能从一个主机块到另一个主机块使用提示值吗?

Cannot I use the prompt value from one host block into another ?

第三,

如何在角色中使用提示?

How can I use prompts in roles ?

推荐答案

vars_prompt 绑定到特定剧本,因此您不能直接在其他剧本中使用它们.尽管您可以在第一部戏中使用 set_fact 来为某个主机设置一个事实,然后在以后的戏中通过 hostvars 来访问它.

vars_prompt are bound to specific play, so you can't use them in other plays directly. Though you can use set_fact in the first play to set a fact for some host, and access it in later plays via hostvars.

提示会在每次播放的开头执行,无论您在 tasks 部分之前还是之后放置 vars_prompt 块都无关紧要(这是YAML词典,位于全部,其中键的顺序并不代表任何含义.

Prompts are executed in the beginning of every play, it doesn't matter where you place vars_prompt block - before or after tasks section (it is a YAML dictionary after all, where sequence of keys doesn't mean anything).

我建议完全不要使用提示,如果您需要一些外部数据,请通过

I'd suggest not to use prompts at all, if you need some external data, pass it via extra variables.

这篇关于剧本中的Vars_prompt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆