i have an ansible as below which simply connects to a given server and runs a script on that server.
name: framework
hosts: target_hosts
vars:
base_dir: /tmp
log_file: "{{ base_dir }}/update_oem_{{ db_unique_name }}_{{ ansible_date_time.iso8601_basic_short }}.log"
become_user: oracle
become: yes
tasks:
- name: Execute module
block:
- name: "Run Update OEM against {{ db_unique_name }} and redirect all output to {{ log_file }}"
shell: "/local/oracle/myapp/workflows/run_update_oracle_home.sh {{ db_unique_name }} > {{ log_file }} 2>&1"
rescue:
- debug:
msg: "Update failed, please engage Support team."
always:
- name: "Now cat the contents {{ log_file }} so that standard out is displayed"
shell: "cat {{ log_file }}"
I now need to add some code in the same code where we can check the log_file for a string 'Error' or 'Traceback',and if the string is found return a failure of the ansible code.
- name: "Searching for an error in log_file"
become: yes
become_user: oracle
register: presence
shell: " egrep -w 'Error|Traceback' {{ log_file }}"
- name: "task in case the error is present in the file"
debug: msg="Script failure"
when: presence is changed
The code is now checking the strings as specified,but is not failing even when they are found.please advise as i am new to ansible.Thanks.