Cisco Router Configuration - match when description is <word> Conditional Check Failed

31 views
Skip to first unread message

Roger Perkin

unread,
Mar 10, 2017, 8:38:49 AM3/10/17
to Ansible Project
I have written this play to run over a Cisco Router- then create a list of interfaces and the idea is to only apply a config to an interface based on the value or not of the descrption. 

The play works fine up until the last point. 

  - block:
    - name: write config to interface
      with_indexed_items: " {{ my_list }} "
      ios_config:
        lines: description CHANGED
        parents: GigabitEthernet{{ item.1 }}
        provider: "{{ cli }}"
        match: none
      when: "' description ANSIBLE' in output.results[{{ item.0 }}].stdout_lines"


It just says conditional check failed 

skipping: [CSR-02] => (item=(1, u'GigabitEthernet2'))  => {
    "changed": false, 
    "item": [
        1, 
        "GigabitEthernet2"
    ], 
    "skip_reason": "Conditional check failed", 
    "skipped": true

All I want to do is for the interface that has a description of Ansible to perform a config change. 

What am I doing wrong?


TASK [show output] *************************************************************
task path: /etc/ansible/playbooks/skip_int.yaml:36
ok: [CSR-02] => (item=(1, u'GigabitEthernet2')) => {
    "invocation": {
        "module_args": {
            "var": "output.results[1].stdout_lines"
        }, 
        "module_name": "debug"
    }, 
    "item": [
        1, 
        "GigabitEthernet2"
    ], 
    "output.results[1].stdout_lines": [
        [
            "Building configuration...", 
            "", 
            "Current configuration : 69 bytes", 
            "!", 
            "interface GigabitEthernet2", 
            " ip address dhcp", 
            " negotiation auto", 
            "end", 
            ""
        ]
    ]
}
ok: [CSR-02] => (item=(0, u'GigabitEthernet1')) => {
    "invocation": {
        "module_args": {
            "var": "output.results[0].stdout_lines"
        }, 
        "module_name": "debug"
    }, 
    "item": [
        0, 
        "GigabitEthernet1"
    ], 
    "output.results[0].stdout_lines": [
        [
            "Building configuration...", 
            "", 
            "Current configuration : 98 bytes", 
            "!", 
            "interface GigabitEthernet1", 
            " description ANSIBLE", 
            " no ip address", 
            " shutdown", 
            " negotiation auto", 
            "end", 
            ""
        ]
    ]
}
ok: [CSR-02] => (item=(2, u'GigabitEthernet3')) => {
    "invocation": {
        "module_args": {
            "var": "output.results[2].stdout_lines"
        }, 
        "module_name": "debug"
    }, 
    "item": [
        2, 
        "GigabitEthernet3"
    ], 
    "output.results[2].stdout_lines": [
        [
            "Building configuration...", 
            "", 
            "Current configuration : 95 bytes", 
            "!", 
            "interface GigabitEthernet3", 
            " description test interface", 
            " no ip address", 
            " negotiation auto", 
            "end", 
            ""
        ]
    ]
}

Kai Stian Olstad

unread,
Mar 10, 2017, 10:02:49 AM3/10/17
to ansible...@googlegroups.com
On 09. mars 2017 20:26, Roger Perkin wrote:
> The play works fine up until the last point.
>
> - block:
> - name: write config to interface
> with_indexed_items: " {{ my_list }} "
> ios_config:
> lines: description CHANGED
> parents: GigabitEthernet{{ item.1 }}
> provider: "{{ cli }}"
> match: none
> * when: "' description ANSIBLE' in output.results[{{ item.0
> }}].stdout_lines"*

Don't use curly brackets in when:, they are implied.
If you do you can get all kind of strange behavior.

when: "' description ANSIBLE' in output.results[item.0].stdout_lines"

--
Kai Stian Olstad

Roger Perkin

unread,
Mar 10, 2017, 4:08:16 PM3/10/17
to Ansible Project, ansible-pr...@olstad.com
Thanks, tried that but it still skips the conditional check. 

Kai Stian Olstad

unread,
Mar 10, 2017, 5:19:33 PM3/10/17
to ansible...@googlegroups.com
On 10. mars 2017 22:08, Roger Perkin wrote:
> Thanks, tried that but it still skips the conditional check.

After checking the variable output I see that the
output.results[item.0].stdout_lines
contains a list of lists so you need to use

output.results[item.0].stdout_lines.0

--
Kai Stian Olstad
Reply all
Reply to author
Forward
0 new messages