Ansible - 执行时需要用户输入的控制命令 [英] Ansible - Control commands when need users input when executing
问题描述
如何在命令执行时控制用户输入并询问我一些问题例如:
How can i control user inputs when a command is executing and ask me something for example :
sudo apt-get install mariadb-server
当您在 ubuntu 中运行此命令时,它要求您为 mysql 用户 root 输入新密码,然后再次要求再次输入密码以进行确认.我如何将变量(例如 mariadbpass)传递给此命令,因为每次 ansible 运行时都会挂起并失败,因此我必须登录服务器并手动运行此
when you run this command in ubuntu it asked you please enter new password for mysql user root and then again it ask to enter password again for confirmation . how can i pass a variable for example mariadbpass to this command because everytime ansible run this hangs and failed so i have to login to servers and run manually this
dpkg --configure -a
输入提示密码及其确认.
to enter prompted password and its confirmation.
谢谢
推荐答案
解决方案如下:在你的剧本中安装 mariadb 10 任务之前添加这个
Here is the Solution : add this before installing mariadb 10 task in your playbook
- name: debconf asking for password
debconf:
name: maria-db-10.0
question: "{{ item }}"
vtype: password
value: "{{ mariadb_root_password }}"
with_items:
- mysql-server/root_password
- mysql-server/root_password_again
这篇关于Ansible - 执行时需要用户输入的控制命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!