ansible:如何在提示中进行字符串插值?

ansible: how to do string interpolation in a prompt?

我怎样才能完成这样的事情?

  vars_prompt:
    new_password: "new password for {{ target_username }}@{{ ansible_hostname }}?"

编辑:基于mgsk's答案,我决定在创建帐户时简单地存储一个默认密码,而不是提示用户。我的 ssh play 无论如何都禁用密码登录,所以实际上我只是想防止由于没有用户输入密码而导致帐户锁定。

所以我写了一个默认密码,然后使用这个处理程序来提醒操作员更改它:

handlers:
  - name: warn default password
    debug: msg="default password installed for {{ target_username }}; be sure to change it"

vars_prompt 是 运行 在事实收集之前。我不认为你可以做到这一点,不能用任何标准的方法。引用 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.

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.

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-devel 邮件列表中的 related discussion