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] *******************************************************************
TASK [role_mhe : Database SELECT Ansible Testing] ******************************
TASK [role_mhe : Log SELECT database output] ***********************************
changed: [target -> localhost]
TASK [role_mhe : Database expect module sqlplus testing] ***********************
TASK [role_mhe : Log EXPECT output] ********************************************
PLAY RECAP *********************************************************************
target : ok=4 changed=3 unreachable=0 failed=0
- name: Database SELECT Ansible Testing
shell: ". ~/.profile;sqlplus <DB Info> @/manh/software/distribution/ansible_db_select_test.sql"
register: db_select_output
- name: Log SELECT database output
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
- "@/manh/software/distribution/ansible_db_select_test.sql"
- name: Log EXPECT output
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