Ansible Expect模块无法匹配字符串/正则表达式脚本问题 [英] Ansible Expect module can't match string/regex script questions

查看:532
本文介绍了Ansible Expect模块无法匹配字符串/正则表达式脚本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试通过Vagrant机器中的Ansible自动执行脚本安装.

我花了很多时间在网上找到解决方案,但是文档和示例都很薄弱.


I'm trying to automate a script installation through Ansible in a Vagrant machine.

I tried a lot to find a solution across the web but the documentation and the examples are very weak.

我正在尝试安装的脚本会提示我正在尝试使用 Ansible Expect模块以编程方式回答的问题.

That script I'm trying to install is prompting questions that I'm trying to answer programmatically with the Ansible Expect Module.

Ansible Task:

-名称:运行Lisk安装"
  成为:True
  成为用户:无业游民
  期望:
     命令:bash installLisk.sh install -r {{env}}
     响应:
                 """""""""" (默认/home/vagrant)':"/home/vagrant"
                       (y/n):':"y"
      echo:是

Ansible Task:

- name: "Running Lisk installation"
  become: True
  become_user: vagrant
  expect:
      command: bash installLisk.sh install -r {{env}}
      responses:
            'Where do you want to install Lisk to? (Default /home/vagrant)': "/home/vagrant"
            'Would like to install NTP? (y/n):': "y"
      echo: yes

似乎无法识别问题或答案,这是我要从配置中获取的错误

任务[危险:运行Lisk的安装] ********************************************

致命:[默认]:失败! => {
已更改":true,
"cmd":"bash installLisk.sh安装-r测试",
"delta":"0:00:30.137468",
"end":"2016-08-26 08:18:46.740017",
失败":true,
"rc":null,
开始":"2016-08-26 08:18:16.602549",

It seems it can't recognize the question or the answer, this is the error I'm getting back from the provisioning

TASK [lisk : Running Lisk installation] ****************************************

fatal: [default]: FAILED! => {
"changed": true,
"cmd": "bash installLisk.sh install -r test",
"delta": "0:00:30.137468",
"end": "2016-08-26 08:18:46.740017",
"failed": true,
"rc": null,
"start": "2016-08-26 08:18:16.602549",

"stdout":检查先决条件:\ r \ n
Curl已安装.\ t \ t \ t \ t \ t \ u001b [32mPassed \ u001b(B \ u001b [m \ r \ n
已安装Tar.\ t \ t \ t \ t \ t \ u001b [32mPassed \ u001b(B \ u001b [m \ r \ n
Wget已安装.\ t \ t \ t \ t \ t \ u001b [32mPassed \ u001b(B \ u001b [m \ r \ n
Sudo已安装并通过身份验证.\ t \ t \ t \ u001b [32mPassed \ u001b(B \ u001b [m \ r \ n \
u001b [32m已通过所有先决条件!\ u001b(B \ u001b [m \ r \ n
您要将Lisk安装到哪里? (默认/home/vagrant):,

"stdout": "Checking prerequisites:\r\n
Curl is installed.\t\t\t\t\t\u001b[32mPassed\u001b(B\u001b[m\r\n
Tar is installed.\t\t\t\t\t\u001b[32mPassed\u001b(B\u001b[m\r\n
Wget is installed.\t\t\t\t\t\u001b[32mPassed\u001b(B\u001b[m\r\n
Sudo is installed and authenticated.\t\t\t\u001b[32mPassed\u001b(B\u001b[m\r\n\
u001b[32mAll preqrequisites passed!\u001b(B\u001b[m\r\n
Where do you want to install Lisk to? (Default /home/vagrant): ",

"stdout_lines":[
检查先决条件:",
已安装卷曲.\ t \ t \ t \ t \ t \ u001b [32mPassed \ u001b(B \ u001b [m,
已安装Tar.\ t \ t \ t \ t \ t \ u001b [32mPassed \ u001b(B \ u001b [m,
已安装Wget.\ t \ t \ t \ t \ t \ u001b [32mPassed \ u001b(B \ u001b [m",
"Sudo已安装并通过身份验证.\ t \ t \ t \ u001b [32mPassed \ u001b(B \ u001b [m",
"\ u001b [32m已通过所有先决条件!\ u001b(B \ u001b [m",
您要将Lisk安装到哪里?(默认/home/vagrant):"
]}

谢谢所有人

"stdout_lines": [
"Checking prerequisites:",
"Curl is installed.\t\t\t\t\t\u001b[32mPassed\u001b(B\u001b[m",
"Tar is installed.\t\t\t\t\t\u001b[32mPassed\u001b(B\u001b[m",
"Wget is installed.\t\t\t\t\t\u001b[32mPassed\u001b(B\u001b[m",
"Sudo is installed and authenticated.\t\t\t\u001b[32mPassed\u001b(B\u001b[m",
"\u001b[32mAll preqrequisites passed!\u001b(B\u001b[m",
"Where do you want to install Lisk to? (Default /home/vagrant): "
]}

Thank you all guys in advance

推荐答案

expect模块中的响应是正则表达式,因此问号具有特殊含义.
您可以简单地使用:

Responses in expect module are regular expressions, so question marks have special meanings.
You can simply use:

- expect:
    command: bash installLisk.sh install -r {{env}}
    responses:
      'install Lisk to': '/home/vagrant'
      'install NTP': 'y'
    echo: yes

这篇关于Ansible Expect模块无法匹配字符串/正则表达式脚本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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