0

Running ansible 2.10.17

I keep getting % Invalid input detected at '^' marker. when trying to run a role. here is my code. Note "filter", "trust", and "untrust" are passed in with -e as extra variables.

-- name: Include vars
  include_vars:
    file: ../../../settings.yaml
    name: settings

- name: Extract tags from trust + untrust variables
  set_fact:
    trust_tag_filter: "{ {{ trust }}.split(':')[0] }"
    untrust_tag_filter: "{ {{ untrust }}.split(':')[0] }"

- name: Routers configuration, filter "{{ filter }}", with trust tag filter "{{ trust_tag_filter }}", and untrust tag filter "{{ untrust_tag_filter }}"
  iosxr_command:
    commands:
    - show run formal object-group network ipv4 | u egrep {{ filter }}
    - show run ipv4 access-list acl_trust_in | u egrep {{ filter }}
    - show run formal interface | u egrep "BVI{{ trust_tag_filter }}"
    - show run formal interface | u egrep "BVI{{ untrust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether21.{{ trust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether21.{{ untrust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether22.{{ trust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether22.{{ untrust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether23.{{ trust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether23.{{ untrust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether24.{{ trust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether24.{{ untrust_tag_filter }}"
    - show run l2vpn bridge group TRUST bridge-domain "VLAN{{ trust_tag_filter }}"
    - show run l2vpn bridge group UNTRUST bridge-domain "VLAN{{ untrust_tag_filter }}"
    - show run router static address-family ipv4 unicast | utility egrep 'router\ static|family|{{settings.lan_subnet_prefix}}{{filter}}|10.30.{{filter}}'
    - show evpn evi | u egrep 'VPN-ID|{{ trust_tag_filter }}|{{ untrust_tag_filter }}'

  register: response

- debug: msg="{{ response.stdout }}"

But when I run it I keep getting this error

The full traceback is:
  File "/tmp/ansible_iosxr_command_payload_kxd7v36e/ansible_iosxr_command_payload.zip/ansible_collections/cisco/iosxr/plugins/module_utils/network/iosxr/iosxr.py", line 586, in run_commands
    return connection.run_commands(commands=commands, check_rc=check_rc)
  File "/tmp/ansible_iosxr_command_payload_kxd7v36e/ansible_iosxr_command_payload.zip/ansible/module_utils/connection.py", line 200, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [router.our.domain]: FAILED! => changed=false
  invocation:
    module_args:
      commands:
      - show run formal object-group network ipv4 | u egrep 89
      - show run ipv4 access-list acl_trust_in | u egrep 89
      - show run formal interface | u egrep "BVI{ 1234:192.168.20.0/29.split(':')[0] }"
      - show run formal interface | u egrep "BVI{ 1235:192.168.30.0/29.split(':')[0] }"
      - show run formal interface | u egrep "Bundle-Ether21.{ 1234:192.168.20.0/29.split(':')[0] }"
      - show run formal interface | u egrep "Bundle-Ether21.{ 1235:192.168.30.0/29.split(':')[0] }"
      - show run formal interface | u egrep "Bundle-Ether22.{ 1234:192.168.20.0/29.split(':')[0] }"
      - show run formal interface | u egrep "Bundle-Ether22.{ 1235:192.168.30.0/29.split(':')[0] }"
      - show run formal interface | u egrep "Bundle-Ether23.{ 1234:192.168.20.0/29.split(':')[0] }"
      - show run formal interface | u egrep "Bundle-Ether23.{ 1235:192.168.30.0/29.split(':')[0] }"
      - show run formal interface | u egrep "Bundle-Ether24.{ 1234:192.168.20.0/29.split(':')[0] }"
      - show run formal interface | u egrep "Bundle-Ether24.{ 1235:192.168.30.0/29.split(':')[0] }"
      - show run l2vpn bridge group TRUST bridge-domain "VLAN{ 1234:192.168.20.0/29.split(':')[0] }"
      - show run l2vpn bridge group UNTRUST bridge-domain "VLAN{ 1235:192.168.30.0/29.split(':')[0] }"
      - show run router static address-family ipv4 unicast | utility egrep 'router\ static|family|10.35.89|10.30.89'
      - show evpn evi | u egrep 'VPN-ID|{ 1234:192.168.20.0/29.split(':')[0] }|{ 1235:192.168.30.0/29.split(':')[0] }'
      interval: 1
      match: all
      provider: null
      retries: 10
      wait_for: null
  msg: |-
    show run formal interface | u egrep "BVI{ 1234:192.168.20.0/29.split(':')[0] }"
                                                                                                   ^
    % Invalid input detected at '^' marker.
    RP/0/RP0/CPU0:router#

Why? Am I not defining the variables correctly?

2
  • 1
    Please start by double checking your example playbook as it is not valid yaml at first glance (double dash on first task and improper indentation) so it is hard to know if this is a copy/paste error or the potential source of your problem. Commented Oct 17, 2023 at 15:40
  • 1
    Moreover please see minimal reproducible example. No one can even try to reproduce this without an iosxr device at end. Your module is complaining about a very precise comane in the list (i.e. the first in the series of show run formal interface ...... Feed that to a debug task get the output and play it manually on your device to see if you get the same error. If the debug output is not what is expected then show exactly what it is supposed to look like. Commented Oct 17, 2023 at 15:50

1 Answer 1

0

Figured it out. Two problems.

  1. I was not splitting properly. Propper way is to split inside the variable
trust_tag_filter: "{{ trust.split(':')[0] }}"
untrust_tag_filter: "{{ untrust.split(':')[0] }}"
  1. I was querying for VLAN with double quotes, had to remove that.
- show run l2vpn bridge group TRUST bridge-domain VLAN{{ trust_tag_filter }}
- show run l2vpn bridge group UNTRUST bridge-domain VLAN{{ untrust_tag_filter }}

Here is the adjusted code:

-- name: Include vars
  include_vars:
    file: ../../../settings.yaml
    name: settings

- name: Extract tags from trust + untrust variables
  set_fact:
    trust_tag_filter: "{{ trust.split(':')[0] }}"
    untrust_tag_filter: "{{ untrust.split(':')[0] }}"

- name: Routers configuration, filter "{{ filter }}", with trust tag filter "{{ trust_tag_filter }}", and untrust tag filter "{{ untrust_tag_filter }}"
  iosxr_command:
    commands:
    - show run formal object-group network ipv4 | u egrep {{ filter }}
    - show run ipv4 access-list acl_trust_in | u egrep {{ filter }}
    - show run formal interface | u egrep "BVI{{ trust_tag_filter }}"
    - show run formal interface | u egrep "BVI{{ untrust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether21.{{ trust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether21.{{ untrust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether22.{{ trust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether22.{{ untrust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether23.{{ trust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether23.{{ untrust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether24.{{ trust_tag_filter }}"
    - show run formal interface | u egrep "Bundle-Ether24.{{ untrust_tag_filter }}"
    - show run l2vpn bridge group TRUST bridge-domain VLAN{{ trust_tag_filter }}
    - show run l2vpn bridge group UNTRUST bridge-domain VLAN{{ untrust_tag_filter }}
    - show run router static address-family ipv4 unicast | utility egrep 'router\ static|family|{{settings.lan_subnet_prefix}}{{filter}}|10.30.{{filter}}'
    - show evpn evi | u egrep 'VPN-ID|{{ trust_tag_filter }}|{{ untrust_tag_filter }}'

  register: response

- debug: msg="{{ response.stdout }}"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.