0

I'm new to Ansible an thus this question may seem silly to more advanced users, I'm not sure if it's possible to do what I'm asking since Ansibel is very limited when it comes to loops and conditionals.

I'm performing tasks on a Virtual Connect switch thus I'm limited to use the raw module.

I have a following STDOUT:

=========================================================================

Profile  Port  Network  PXE/IP      MAC Address       Allocated  Status  
                Name    Boot Order                     Speed             
                                                      (min-max)          
=========================================================================
CLO01ES  1     CLO_355  UseBIOS/Au  00-17-A4-77-58-0  -- --      OK      
X02            _1       to          0                                    
-------------------------------------------------------------------------
CLO01ES  2     CLO_355  UseBIOS/Au  00-17-A4-77-58-0  -- --      OK      
X02            _2       to          2                                    
-------------------------------------------------------------------------
CLO01ES  3     Multipl  UseBIOS/Au  00-17-A4-77-58-0  -- --      OK      
X02            e        to          4                                    
               Network                                                   
-------------------------------------------------------------------------
CLO01ES  4     Multipl  UseBIOS/Au  00-17-A4-77-58-0  -- --      OK      
X02            e        to          6                                    
               Network                                                   
-------------------------------------------------------------------------
<omitted>

The issue is that STDOUT can have multiple lines with different profiles in them i.e. I don't know the line numbers or MAC addresses beforehand.

What I want to achive is a status check. If Profile CLO01ESX02 has Network Name: Multiple Network twice, then I want to skip the task.

Whenever I was googling parsing variables or STDOUT I would get just basic answers.

Is this possible with Ansible or am I forced to write a custom script?

techraf
  • 64,883
  • 27
  • 193
  • 198
MMT
  • 1,931
  • 3
  • 19
  • 35

1 Answers1

0

It can't be done directly by any native Ansible modules but using shell command should do the trick.

- name: Check output
  command: <your_command_here> | grep CLO01ESX02 | grep "Multiple Network" | wc -l
  register: wc
  failed_when: wc.stdout|int > 1
Chris Lam
  • 3,526
  • 13
  • 10