Hello - I am working through some seemingly inconsistent results for regex search results in where clauses.
I'm trying to take actions when stdout contains a certain regex pattern. I have one method using shell module, and now testing using a preferred expect module that I'm trying to get to work. The shell method properly logs based on the when-search conditional. The expect skips the same conditional, despite writing output for the same script. Below I have pasted the play, code, and both outputs for reference. I'm new to Ansible, so perhaps I'm missing something obvious. I would expect that both conditionals would pass, but that doesn't seem to be the case. Thoughts? *Play:* [/opt/wmspt]$ ansible-playbook pb_mhe.yml --tags="db","db_expect" PLAY [MHE Config] ************************************************************** TASK [setup] ******************************************************************* ok: [target] TASK [role_mhe : Database SELECT Ansible Testing] ****************************** changed: [target] TASK [role_mhe : Log SELECT database output] *********************************** changed: [target -> localhost] TASK [role_mhe : Database expect module sqlplus testing] *********************** changed: [target] TASK [role_mhe : Log EXPECT output] ******************************************** skipping: [target] PLAY RECAP ********************************************************************* target : ok=4 changed=3 unreachable=0 failed=0 [/opt/wmspt]$ *Code:* - name: Database SELECT Ansible Testing tags: db shell: ". ~/.profile;sqlplus <DB Info> @/manh/software/distribution/ansible_db_select_test.sql" register: db_select_output - name: Log SELECT database output tags: db local_action: copy content="{{ db_select_output.stdout }}" dest={{ log_dir }}/WM_db_select_{{ inventory_hostname }}-{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}.log when: db_select_output.stdout | search("[-]+\n[\s]*0\n") - name: Database expect module sqlplus testing tags: db_expect expect: command: "/bin/bash" responses: \$ $: - . ~/.profile - sqlplus <DB Info> - exit SQL> $: - "@/manh/software/distribution/ansible_db_select_test.sql" - quit timeout: 5 echo: yes register: expect_output - name: Log EXPECT output tags: db_expect local_action: copy content="{{ expect_output.stdout }}" dest={{ log_dir }}/WM_expect_{{ inventory_hostname }}-{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}.log when: expect_output.stdout | search("[-]+\n[\s]*0\n") *Shell module output:* SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 3 15:09:25 2016 Copyright (c) 1982, 2014, Oracle. All rights reserved. Last Successful login time: Thu Nov 03 2016 14:51:18 -05:00 Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Advanced Analytics and Real Application Testing options USE_HTTPS ---------- 0 Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Advanced Analytics and Real Application Testing options *Expect module output (with when conditional commented out):* [/opt/wmspt]$ . ~/.profile [/opt/wmspt]$ sqlplus <DB info> SQL*Plus: Release 12.1.0.2.0 Production on Thu Nov 3 15:09:27 2016 Copyright (c) 1982, 2014, Oracle. All rights reserved. Last Successful login time: Thu Nov 03 2016 15:09:25 -05:00 Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Advanced Analytics and Real Application Testing options SQL> @/manh/software/distribution/ansible_db_select_test.sql USE_HTTPS ---------- 0 Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP, Advanced Analytics and Real Application Testing options [/opt/wmspt]$ exit exit -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1134bb53-6bfc-4605-895f-3fdfab0dbfbd%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.