在变量中使用 ansible --ask-become-pass

Tob*_*biM 4 expect ansible

我需要在期望脚本中使用我的 --ask-become-pass 密码。有没有办法使用在变量中启动 ansible_playbook 时输入的密码?

伪代码:

# ansible-playbook --become --ask-become-pass -i testing master.yml
BECOME password: secretpassword

Run Code Online (Sandbox Code Playgroud)

然后在任务中

- name: use pw variable in task
  expect:
   command: /bin/bash -c "/usr/bin/my_command"
   responses:
     Password: "{{ prompted_pass }}"
Run Code Online (Sandbox Code Playgroud)

在阅读“密码”提示时,我希望输入“secretpassword”

我知道“become_user”,不幸的是它对我的情况没有帮助,因为远程服务器要求输入密码 - 但它与“become_password”相同。

我尝试转储变量和环境,但找不到任何有用的东西。

谢谢,托比亚斯

Joh*_*ald 5

不可以。剧本无法使用交互式密码。

一种替代方法是不使用密码--ask-become-pass,而是将密码作为变量提供。将变量定义ansible_become_password为查找表达式,它从您使用的任何秘密存储中获取密码。也可以使用此变量作为其他程序的密码。

  • 游戏中的“vars_prompt:”关键字用于输入“ansible_become_password”是让键盘输入到 Ansible 的另一种合理方法。 (3认同)