I have a requirement as mentioned below.
I have to access the last column from the table, shown below, of data (obtained from the remote node), using an Ansible playbook.
PROGRESS: Starting connection towards ss7caf stack...
Please wait, the output can take up to several minutes
Blade | EP | AS | Paths (* - current data | Path
Id | Id | Id | transfer path) | State
------+----+-----+-------------------------------+---------
PL-3 | 1 | 1-1 | 10.201.176.0 - 10.116.178.161 | Active
| | | 10.201.176.0 - 10.116.178.162 | Blocked
| | | 10.201.176.2 - 10.116.178.161 | Blocked
| | | 10.201.176.2 - 10.116.178.162 | Inactive
PL-4 | 1 | 4-1 | 10.201.176.0 - 10.250.161.130 | Active
| | | 10.201.176.0 - 10.250.161.138 | Blocked
| | | 10.201.176.2 - 10.250.161.130 | Inactive
This table was generated: 2022-03-08 11:11:38 AEDT
I have to use the content of the last column in a conditional statement to draw some conclusions based on it.
For example, the paths which are specified in the last but one column, corrsponding to the blade ID mentioned in column 1
- are in working condition if the value/content in the last (i.e.,Path state) column is either Active or Blocked
- are in non-working condition if the value/content in the last (i.e.,Path state) column is Inactive
I have tried a playbook like this.
---
# The objective of this playbook is to use this command "sudo dsc-show-sctp-assoc"
# and check the status of Check the status of SCTP Associations.
- name: Playbook for Checking the status of SCTP Associations
hosts: all
become: true
tasks:
- name: Getting SCTP Association status details and saving them to a text file
shell: dsc-show-sctp-assoc | tee sctp.txt # "dsc-show-sctp-assoc" is used to get the tabular data from the remote node
- name: IDNETIYING THE PASS AND FAIL CASES
shell: cat sctp.txt | awk -F "|" {if ($NF=="Inactive") print $0, " ", '===>', "FAIL"; else print $0, " ", "====>","PASS";}'
register: pass_fail_cases
- name: PRINTING THE PASS AND FAIL CASES
debug:
msg: "{{pass_fail_cases.stdout_lines }}"
...
The expected output is shown below
PROGRESS: Starting connection towards ss7caf stack...
Please wait, the output can take up to several minutes
Blade | EP | AS | Paths (* - current data | Path
Id | Id | Id | transfer path) | State
------+----+-----+-------------------------------+---------
PL-3 | 1 | 1-1 | 10.201.176.0 - 10.116.178.161 | Active ===> "PASS"
| | | 10.201.176.0 - 10.116.178.162 | Blocked ===> "PASS"
| | | 10.201.176.2 - 10.116.178.161 | Blocked ===> "PASS"
| | |*10.201.176.2 - 10.116.178.162 | Inactive ===> "FAIL"
PL-3 | 1 | 4-1 | 10.201.176.0 - 10.250.161.130 | Active ===> "PASS"
| | | 10.201.176.0 - 10.250.161.138 | Blocked ===> "PASS"
| | | 10.201.176.2 - 10.250.161.130 | Inactive ===> "FAIL"
This table was generated: 2022-03-08 11:11:38 AEDT
whereas I am getting the below output
PROGRESS: Starting connection towards ss7caf stack...
Please wait, the output can take up to several minutes
Blade | EP | AS | Paths (* - current data | Path
Id | Id | Id | transfer path) | State
------+----+-----+-------------------------------+---------
PL-3 | 1 | 1-1 | 10.201.176.0 - 10.116.178.161 | Active ===> "PASS"
| | | 10.201.176.0 - 10.116.178.162 | Blocked ===> "PASS"
| | | 10.201.176.2 - 10.116.178.161 | Blocked ===> "PASS"
| | |*10.201.176.2 - 10.116.178.162 | Inactive ===> "PASS"
PL-3 | 1 | 4-1 | 10.201.176.0 - 10.250.161.130 | Active ===> "PASS"
| | | 10.201.176.0 - 10.250.161.138 | Blocked ===> "PASS"
| | | 10.201.176.2 - 10.250.161.130 | Inactive ===> "PASS"
This table was generated: 2022-03-08 11:11:38 AEDT
I guess that the conditional statement (if condition) of AWK command is not working as expected and hence everything is resulted as "PASS".
I tried it multiple ways. But none of them gave me the expected output.
Can someone please help to let me know where I am going wrong?
PS: I tried using AWK command here. Please suggest me the other approcahes that I can follow to get the expected output, if any