Ansible在类似linux的操作系统上回答我需要回答的问题
我有一个DataDomain系统,可以通过ssh进入。我需要在DataDomain上自动执行一个过程,该过程会在命令后询问:Ansible在类似linux的操作系统上回答我需要回答的问题,ansible,ansible-module,Ansible,Ansible Module,我有一个DataDomain系统,可以通过ssh进入。我需要在DataDomain上自动执行一个过程,该过程会在命令后询问: storage add tier active dev3 Object-store is not enabled. Filesystem will use block storage for user data. Do you want to continue? (yes|no) [no]: yes 我确实尝试了Ansible,并且使用了原始模块 - name
storage add tier active dev3
Object-store is not enabled. Filesystem will use block storage for user data.
Do you want to continue? (yes|no) [no]: yes
我确实尝试了Ansible,并且使用了原始模块
- name: add dev3 active tier
raw: storage add tier active dev3
register: RESULT
这是失败的:
TASK [add dev3 active tier] *******************************************************************************************************************************************************************
fatal: [3.127.218.96]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 9, "stderr": "Shared connection to 3.127.218.96 closed.\r\n", "stderr_lines": ["Shared connection to 3.127.218.96 closed."], "stdout": "\r\n**** Could not add storage: system capacity exceeds the limit allowable by the license.\r\n\r\n", "stdout_lines": ["", "**** Could not add storage: system capacity exceeds the limit allowable by the license.", ""]}
- name: add dev3 active tier
raw: |
yes | storage add tier active dev3
register: RESULT
以下ansible playbook在以下方面也存在缺陷:
TASK [add dev3 active tier] *******************************************************************************************************************************************************************
fatal: [3.127.218.96]: FAILED! => {"changed": true, "msg": "non-zero return code", "rc": 9, "stderr": "Shared connection to 3.127.218.96 closed.\r\n", "stderr_lines": ["Shared connection to 3.127.218.96 closed."], "stdout": "\r\n**** Could not add storage: system capacity exceeds the limit allowable by the license.\r\n\r\n", "stdout_lines": ["", "**** Could not add storage: system capacity exceeds the limit allowable by the license.", ""]}
- name: add dev3 active tier
raw: |
yes | storage add tier active dev3
register: RESULT
expect模块不接受原始数据,并且正在失败
- name expect for add dev3 active tier
expect:
raw: storage add tier active dev3
responses:
Question:
- Do you want to continue? (yes|no) [no]: y
timeout: 30
register: RESULT
你知道我如何用yes捕捉问题和答案吗?默认情况下,
yes
命令发送一个y
。但是您的命令需要一个yes
。您可以传递yes
命令的字符串以重复
-名称:添加dev3活动层
外壳:
cmd:yes是|存储添加层活动dev3
寄存器:结果
您的expect
任务的问题来自两个方面:
首先,事实是:
回答下面的问题或关键是python正则表达式匹配
资料来源:
因此,您必须对每个可能在正则表达式中有意义的符号进行转义。
在您的情况下,这些符号是?
,(
,,)
,[
和]
注意:这些类型或行为很容易在以下正则表达式工具中测试:
其次,responses
键有两种格式,您在这里混合了这两种格式
- 要么你有
响应:
问题:
-答复1
-响应2
-答复3
您不指定脚本中的问题,而是指定一系列答案。当然,只有当问题和回答总是以相同的顺序出现时,这才起作用
- 要么你用
响应:
这是脚本中问题的提示:这就是答案
这是另一个问题:下面是相应的答案
在这里,您可以确定您正确地将每个答案映射到相应的问题。请注意,本词典中没有问题,答案是词典的关键,而不是列表
因此,对于您的用例,expect的正确用法是:
-期望:
命令:存储添加层活动dev3
响应:
是否要继续\\(是\ \否\)\[否\]:“是”
超时时间:30
寄存器:结果