Ansible 与思科设备

Ansible with cisco devices

我尝试通过以下任务在 cisco 设备上测试我的审核 activity;

  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'

此 activity 将 运行 ios 命令和寄存器值,之后我将检查条件并将结果粘贴到我的本地主机(linux) 但是我遇到了这个错误;

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"}

谁能告诉我发生了什么事? PS。我的 ansible 版本是 2.9.3

您存储在“output1”变量中的结果包含在 'output1.stdout[0]' 中。

'output1.stdout' 是一个列表,'output1.stdout[0] 是您要查找的字符串。