简体   繁体   中英

Trying to use 'selectattr in' filter with Ansible playbook but it fails as per the playbook below

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM