I have a DataDomain System which I can enter via ssh. I need to automate a procedure on the DataDomain which does aks a question after a command:
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
I do try this with Ansible and do use the raw module
- name: add dev3 active tier
raw: storage add tier active dev3
register: RESULT
This is failing with:
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.", ""]}
the following ansible-playbook is also failing with:
- name: add dev3 active tier
raw: |
yes | storage add tier active dev3
register: RESULT
expect module does not accept raw and is also failing.
- 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
Any idea how I can catch the question and answer with yes?
The issue with your
expect
task is coming from two things:First, the fact that:
Source: https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect_module.html#notes
So you will have to escape each and every symbol that might have a meaning in a regex.
In your case those symbols are
?
,(
,|
,)
,[
and]
.Note: those kind or behaviour are easily testable in regex tools like this one: https://regex101.com/r/ubtVfH/1/
Second, the
responses
key have two format that you mixed here.Question
key in this dictionary and that the answers are the keys of a dictionary, and not a list.So for your use case, the proper use of expect would be: