-1

I try to test my audit activity on cisco device by the following task;

  tasks:
    - name: 1.1.1 Enable 'aaa new-model' (Scored)
      ios_command:
        commands: show running-config | incl aaa new-model
      register: output1
    - name: 1.1.1 Check results
      delegate_to: localhost
      lineinfile:
        path: /tmp/Summary.txt
        line: "1.1.1|Fail"
      when: output1.stdout is 'no aaa new-model'
    - name: 1.1.1 Check results
      delegate_to: localhost
      lineinfile:
        path: /tmp/Summary.txt
        line: "1.1.1|Pass"
      when: output1.stdout is not 'no aaa new-model'

This activity will run ios command and register values after that I will check for condition and paste the result to my localhost(linux) but I got this errors;

FAILED! => {"msg": "The conditional check 'output1.stdout is 'no aaa new-model'' failed. The error was: template error while templating string: expected token 'name', got 'string'. String: {% if output1.stdout is 'no aaa new-model' %} True {% else %} False {% endif %}\n\nThe error appears to be in '/etc/ansible/Cisco/1.1.yaml': line 15, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n      register: output1\n    - name: 1.1.1 Check results\n      ^ here\n"}

Can anyone tell me what happens? PS. My ansible version is 2.9.3

1 Answers1

0

The result you stored in the "output1" variable is contained in 'output1.stdout[0]'.

'output1.stdout' is a list, and 'output1.stdout[0] is the string you are after.

Pluppo
  • 71
  • 6