I am stumped…I have been trying to use the expect module and format the expected response as a regex that can match multiple responses. I see posts all over where people are trying to match the response exactly and have to escape the regex special characters. It seems nobody writes regex to match multiple responses. Is this not possible?
Playbook
- name: Clear Permissions on /var/etc/pam.conf
hosts: juniper_ex4200
tasks: - name: Access member 0
expect:
command: ‘request session member 0’
responses: “^—\sJUNOS.+\n(warning.+\n){5}{((backup)|(linecard)):((1)|(2))}”: “start shell user root”
Error
ERROR! Syntax Error while loading YAML.
The error appears to have been in ‘/home/dwilliams/ex4200_permissions_clear/ex4200_permissions_clear’: line 8, column 25, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
command: ‘request session member 0’
responses: “^—\sJUNOS.+\n(warning.+\n){5}{((backup)|(linecard)):((1)|(2))}”
^ here
This one looks easy to fix. It seems that there is a value started
with a quote, and the YAML parser is expecting to see the line ended
with the same kind of quote. For instance:
when: “ok” in result.stdout
Could be written as:
when: ‘“ok” in result.stdout’
Or equivalently:
when: “‘ok’ in result.stdout”