I am trying to use textfsm to parse the data for admin show platform in that anything with a state of 'IOS XR RUN' 'READY' or 'OK' will pass & anything else will report failed. I'm using the selectattr in option but get the following error - "msg": "The task includes an option with an undefined variable. The error was: 'intf_tests_pass' is undefined. Any ideas why this is failing as the working_state variable is defined.
name: Collect admin show platform info iosxr_command: commands: - admin show platform provider: "{{ cli }}" register: platform_result when: device_os == 'cisco-ios-xr'
name: retrieve status to be returned set_fact: working_state: ['IOS XR RUN', 'READY', 'OK']
name: parse platform_result textfsm_parser: file: templates_textfsm/{{ device_os }}/admin_show_platform.template content: "{{ platform_result.stdout.0 }}" name: platform_state when:
- platform_result.stdout is defined
- platform_result.stdout[0] != none
- platform_result.stdout[0] != ""
name: identify platform_result that passed set_fact: platform_tests_pass: "{{ ansible_facts.platform_state | selectattr('STATE', 'in', 'working_state') | list }}" when: ansible_facts.platform_state is defined
name: identify platform_result that failed set_fact: platform_tests_fail: "{{ ansible_facts.platform_state | difference(platform_tests_pass) | list}}" when: ansible_facts.platform_state is defined
debug: msg:
- "{{ intf_tests_pass }}"
- "{{ intf_tests_fail }}"
Thanks, Brian