Ansible:期望 ->命令名无效 [英] Ansible: expect -> invalid command name

查看:34
本文介绍了Ansible:期望 ->命令名无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用带有 ansible 的 expect 函数来安装带有 preanswers 的 .bin 文件.但我收到此错误.

I want to use the expect function with ansible to install a .bin file with preanswers. But i get this error.

"stderr": "invalid command name \"/opt/atlassian-jira-software-7.8.1-x64.bin\"\n    while executing\n\"/opt/atlassian-jira-software-7.8.1-x64.bin\"",

但是我也不能执行其他unix简单命令...

However also i cant execute other unix simple commands...

我的代码:

- name: Upgrade Jira
   shell: |
     /opt/{{ jiraExec }}

     expect "OK [o, Enter], Cancel [c]"
     send "o\n"

     expect "Express Install (use default settings) [1], Custom Install (recommended for advanced users) [2], Upgrade an existing JIRA installation [3, Enter]"
     send "3\n"

     expect "[/opt/atlassian/jira]"
     send "\n"

     expect "Yes [y, Enter], No [n]"
     send "y\n"

     expect "Upgrade [u, Enter], Exit [e]"
     send "u\n"

     expect "Yes [y, Enter], No [n]"
     send "n\n"
  args:
     executable: /usr/bin/expect

而且我无法使用 pexpect 模块.

And i have no possibility to use the pexpect module.

推荐答案

您缺少 spawn 命令:

You are missing the spawn command:

spawn /opt/{{ jiraExec }}

此外,对于任何包含 [...] 的字符串,请使用 Tcl 的单引号机制:方括号是 Tcl 的命令替换语法(想想 sh 中的反引号):

Also, for any string containing [...] use Tcl's single quoting mechanism: the square brackets are Tcl's command substitution syntax (think backticks in sh):

expect {OK [o, Enter], Cancel [c]}

我发现了一个类似的例子:https://docs.ansible.com/ansible/latest/modules/shell_module.html?highlight=shell#examples

I found a similar example: https://docs.ansible.com/ansible/latest/modules/shell_module.html?highlight=shell#examples

这篇关于Ansible:期望 ->命令名无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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