1

What I am doing : I am reading a file using shell module and get the unique error code from the entire file , the result of this is result.out I am local file file1 which have list of known error code Now i want to check if any value of result.out match in file1 then restart the service

I can achive this using following command in shell

 hosts: tsm_client                                                                                                   
 remote_user: root                                                                                                   
 vars_file: error_code                                                                                               
 tasks:                                                                                                              
   - name: Read error file code                                                                                      
     shell: "cat /tsm_error/dsmerrorlog.log |cut -d ' ' -f 5 |sort | uniq | egrep 101|102|103|104 | cat "        
     register: output                                                                                                
     ignore_errors: true                                                                                             
     #- debug: var=output.stdout_lines                                                                               

   - name: Restart Cron Service                                                                                      
     service:                                                                                                        
       name: crond                                                                                                   
       state: restarted                                                                                              
     when: output.stdout != ""                                                                                       

   - debug: msg='Error Code does not macth Please cont to Backup'                              
     when: output.stdout == ""                                                                                       

Could you please help me use ansible module instead of shell with grep

  • Share a sample of original error log file you are processing. Based on that we can decide which filter to use. How does the data look like in dsmerrorlog.log? – Uttam Apr 05 '20 at 11:06
  • 27/02/20 20:32:20 ANS1228E Sending of object '/home/sdda/apps/clickhouse-bfg/data/data/sdda_prod1/INTRADAY_POSITION/e112047d49c0a63f1ace7eae70f3338f_16797_16852_11' failed. 27/02/20 20:32:20 ANS4005E Error processing '/home/sdda/apps/clickhouse-bfg/data/data/sdda_prod1/INTRADAY_POSITION/e112047d49c0a63f1ace7eae70f3338f_16797_16852_11': file not found 27/02/20 20:32:22 ANS1228E Sending of object '/home/sdda/apps/clickhouse-bfg/data/data/sdda_prod1/INTRADAY_POSITION/e112047d49c0a63f1ace7eae70f3338f_16853_16853_0' failed – Dharmendra Singh Apr 05 '20 at 14:30
  • Basically I am trying to do 1- Get client node details from tsm server which have missed their daily backup 2- Read the error.logs in clients nodes 3- Match any error code in error logs of client node from my local error code list 4- Need to restart the client node service when code match in logs Error code in log file ANS1228E, ANS4005E Sample client error logs 27/02/20 20:32:20 ANS1228E Sending of object '/home/sdda/apps/clickhouse-bfg/data/data/sdda_prod1/INTRADAY_POSITION/e112047d49c0a63f1ace7eae70f3338f_16797_16852_11' failed. – Dharmendra Singh Apr 05 '20 at 14:57
  • I guess this is possible duplicate of question: https://stackoverflow.com/questions/38461920/ansible-check-if-string-exists-in-file – Tejas Sarade Apr 05 '20 at 20:07
  • No .. This is not .. The link which you gave , is finding a single value from the list , but what i need to do it i need to find multiple values from one list to another list , as replacement of egrep – Dharmendra Singh Apr 06 '20 at 09:00

0 Answers0