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:
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:
Thanks, Brian
Based on the output you posted, you saved facts to platform_tests_pass and platform_tests_fail, not intf_tests_pass and intf_tests_fail, so those variables are never actually defined.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.