是否有条件提示输入变量? [英] Ansible to Conditionally Prompt for a Variable?

查看:82
本文介绍了是否有条件提示输入变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够提示输入我的超级安全密码变量,如果该变量尚未在环境变量中. (我想我可能不想将定义放入.bash_profile或其他位置之一.)

I would like to be able to prompt for my super secure password variable if it is not already in the environment variables. (I'm thinking that I might not want to put the definition into .bash_profile or one of the other spots.)

这不起作用.它总是提示我.

This is not working. It always prompts me.

vars:
  THISUSER: "{{ lookup('env','LOGNAME') }}"
  SSHPWD:   "{{ lookup('env','MY_PWD') }}"

vars_prompt:
  - name: "release_version"
    prompt: "Product release version"
    default: "1.0"
    when: SSHPWD == null

注意::我在Mac上,但是我希望所有解决方案都与平台无关.

NOTE: I'm on a Mac, but I'd like for any solutions to be platform-independent.

推荐答案

根据 devs 以及我对最新版本所做的快速测试,vars_prompt "GATHERING FACTS"之前运行.这意味着在使用when进行检查时,env var SSHPWD始终为null.

According to the replies from the devs and a quick test I've done with the latest version, the vars_prompt is run before "GATHERING FACTS". This means that the env var SSHPWD is always null at the time of your check with when.

不幸的是,似乎没有办法在任务级别允许vars_prompt语句.

Unfortunately it seems there is no way of allowing the vars_prompt statement at task level.

Michael DeHaan的理由是,允许在任务级别进行提示将打开角色提出很多问题的大门.这将使使用Ansible Galaxy角色变得困难:

Michael DeHaan's reasoning for this is that allowing prompts at the task-level would open up the doors to roles asking a lot of questions. This would make using Ansible Galaxy roles which do this difficult:

Ansible中一直坚定地强调自动化,而在任务级别提出问题并不是我们真正想要做的事情.

There's been a decided emphasis in automation in Ansible and asking questions at task level is not something we really want to do.

但是,您仍然可以在游戏级别上询问vars_prompt问题,并在整个任务中使用这些变量.你只是不能问角色问题.

However, you can still ask vars_prompt questions at play level and use those variables throughout tasks. You just can't ask questions in roles.

实际上,这就是我要执行的-如果很多Galaxy角色开始提出问题,我会发现这很烦人:)

And really, that's what I would like to enforce -- if a lot of Galaxy roles start asking questions, I can see that being annoying :)

这篇关于是否有条件提示输入变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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