我想使用带有ansible的expect函数来安装带有preanswers的.bin文件。但我得到了这个错误。
"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简单命令......
我的代码:
- 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模块。
答案 0 :(得分:1)
您缺少spawn命令:
spawn /opt/{{ jiraExec }}
此外,对于包含[...]
的任何字符串,使用Tcl的单引号机制:方括号是Tcl的命令替换语法(想想sh中的反引号):
expect {OK [o, Enter], Cancel [c]}
我找到了一个类似的例子:https://docs.ansible.com/ansible/latest/modules/shell_module.html?highlight=shell#examples
答案 1 :(得分:0)
错误没有抱怨expect
,请检查您的Jira文件路径,您应该考虑使用JIRA unattended installation
- name: Upgrade Jira
shell: /opt/atlassian-jira-software-X.X.X-x64.bin -q -varfile response.varfile
其中jira-software.X.X.X是您下载的JIRA版本。
-q指示安装程序以无人参与模式(安静地)运行。