需要使用Ansible自动安装cisco anyconnect。在运行安装脚本时,它要求同意条款和条件。如何解析&;yes &;?下面的第一种方法显然是有效的(没有尝试过),但根据这个Ansible文档需要Python 2.6;我需要python3的解。下面第二个方法也行不通。
剧本代码:
- name: Install CISCO annyconnect #>>>> needs pexpect module from python2 <<<<
become: yes
expect:
command: "/opt/CISCO/{{ vpn }}/vpn/vpn_install.sh"
responses:
Question:
- yes
- name: Install CISCO annyconnect
become: yes
shell: yes | "/opt/CISCO/{{ vpn }}/vpn/vpn_install.sh"
Cisco VPN安装脚本:
.
.
.
Description of Other Rights and Obligations
Please refer to the Cisco Systems, Inc. End User License Agreement.
http://www.cisco.com/en/US/docs/general/warranty/English/EU1KEN_.html
Do you accept the terms in the license agreement? [y/n]
解决方案不需要python 2.6,而是python>= 2.6.
"响应"背后的逻辑映射是,当在输出中找到左侧时,它将用右侧响应程序。其思想是查找输入提示符,当找到提示符时,响应。
所以,目前你的示例代码正在寻找"Question"在程序输出中(可能不匹配任何内容),但它应该寻找其他字符串,告诉我们它需要输入。你接受吗?看起来是个不错的人选。
- name: Install CISCO annyconnect #>>>> needs pexpect module from python2 <<<<
become: yes
expect:
command: "/opt/CISCO/{{ vpn }}/vpn/vpn_install.sh"
responses:
"Do you accept": y