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

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

问题描述

如果我的超级安全密码变量不在环境变量中,我希望能够提示它.(我想我可能不想将定义放入 .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"运行事实".这意味着在使用 when 检查时,环境变量 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 :)

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

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