0

I am trying to check if a condition is met using the wait_for argument on a task:

- name: GET SHOW PORT SECURITY INTRUSION OUTPUT
  arubanetworks.aos_switch.arubaoss_command:
    commands:
      - "show port-security intrusion-log | i ^  {{item.Port}}    ."
    wait_for: result[0] contains '  1     bc9fe4-c653a4'
  register: port_security_intrusion_output
  when: 
    - int_brief_filtred.msg | length > 0
  loop: "{{ int_brief_filtred.msg }}"

This way, the playbook will only move to the next task if the condition is met. The problem is: This string will vary, but always following the same pattern.

AWX version: < AWX 21.13.0 > ansible module: arubaoss_command ansible collection: arubanetworks.aos_switch

On the documentations I only found the possibility of evaluating pure strings, not regex.

Is there a wait_for condition option like this? wait_for: result[0] matches(\s+......-......)

Zeitounator
  • 38,476
  • 7
  • 53
  • 66
ExploitZ
  • 13
  • 5
  • 1
    What is unclear in the [documentation example](https://github.com/aruba/aos-switch-ansible-collection/blob/master/plugins/modules/arubaoss_command.py#L200C9-L210) for your above module which shows exactly what you are looking for? Note that the [similar module in `ansible.community` collection](https://docs.ansible.com/ansible/latest/collections/community/network/aruba_command_module.html#examples) shows almost the same example. If you have already tried something similar, please [edit] and provide a [mre]. – Zeitounator Aug 30 '23 at 17:44

1 Answers1

0

As you can see in all of the documentation, all the examples only uses the keyword "contains". They dont show other possibilities such as "find" or "regex". I tested them and didnt work. The only thing that worked and its not in the documentation is the "not contains". And with a combination of "contains" AND "not contains", i was capable to achieve what i needed:

  - name: GET SHOW PORT SECURITY INTRUSION OUTPUT
      arubanetworks.aos_switch.arubaoss_command:
        commands:
          - "show port-security intrusion-log | i ^  {{item.Port}}  ."
        wait_for: 
          - result[0] contains '  {{item.Port}}  '
          - result[0] not contains 'Mode'
        match: all
      register: port_security_intrusion_output
      when: 
        - int_brief_filtred.msg | length > 0
      loop: "{{ int_brief_filtred.msg }}"
ExploitZ
  • 13
  • 5