首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不允许Playbook保存telnet显示运行命令到文件语法错误

不允许Playbook保存telnet显示运行命令到文件语法错误
EN

Stack Overflow用户
提问于 2019-08-27 10:04:13
回答 1查看 2.8K关注 0票数 0

我正面临着我的游戏手册的语法问题。我试图使用ansible的telnet模块显示命令,如下所示:module.html#telnet-module --它工作得很好--但我的问题是,当我试图添加寄存器将输出存储到一个变量以保存到文本文件中时,它会给我一个错误,说明变量不存在,指示复制任务的错误行。

我尝试过添加空格,并对其做了一些更改,但错误仍在显示。

代码语言:javascript
复制
---
- hosts: telnet
  gather_facts: true
  connection: local

  tasks:
   - name: run show commands
     telnet:
       user: cisco
       password: cisco
       login_prompt: "Username: "
       prompts:
         - "[>#]"
       commands:
         - terminal length 0
         - show version
     register: output


   - copy:
       content: "{{ output.stdout[0] }}"
       dest: "/home/user/telnettest.txt"
代码语言:javascript
复制
TASK [copy] **************************************************************************task path: /home/user/telnet.yaml:20
fatal: [IP]: FAILED! => {
    "msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'\n\nThe error appears to be in '/home/user/telnet.yaml': line 20, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n   - copy:\n     ^ here\n"
}

调试任务的输出:

代码语言:javascript
复制
TASK [debug] ***************************************************************************************************************************************************************
ok: [10.149.71.200] => {
    "msg": {
        "changed": true,
        "failed": false,
        "output": [
            "terminal length 0\r\nTHOSTNAME#",
            "show version\r\nCisco IOS Software,  Software (), Version , RELEASE SOFTWARE (fc3)\r\nTechnical Support: http://www.cisco.com/techsupport\r\nCopyright (c) 1986-2016 by Cisco Systems, Inc.\r\nCompiled Wed 17-Aug-16 13:28 by prod_rel_team\r\nImage text-base: 0x01000000, data-base: 0x02F00000\r\n\r\nROM: Bootstrap program is C3750 boot loader\r\nBOOTLDR: C3750 Boot Loader (C3750-HBOOT-M) Version 12.2(44)SE5, RELEASE SOFTWARE (fc1)\r\n\r\nHOSTNAME uptime is 6 weeks, 6 days, 6 hours, 12 minutes\r\nSystem returned to ROM by power-on\r\nSystem image file is \"flash:c3750-ipservicesk9-mz.122-55.SE11.bin\"\r\n\r\n\r\nThis product contains cryptographic features and is subject to United\r\nStates and local country laws governing import, export, transfer and\r\nuse. Delivery of Cisco cryptographic products does not imply\r\nthird-party authority to import, export, distribute or use encryption.\r\nImporters, exporters, distributors and users are responsible for\r\ncompliance with U.S. and local country laws. By using this product you\r\nagree to comply with applicable laws and regulations. If you are unable\r\nto comply with U.S. and local laws, return this product immediately.\r\n\r\nA summary of U.S. laws governing Cisco cryptographic products may be found at:\r\nhttp://www.cisco.com/wwl/export/crypto/tool/stqrg.html\r\n\r\nIf you require further assistance please contact us by sending email to\r\nexport@cisco.com.\r\n\r\ncisco WS-C3750-24P (PowerPC405) processor (revision J0) with 131072K bytes of memory.\r\nProcessor board ID CAT1037NGMH\r\nLast reset from power-on\r\n2 Virtual Ethernet interfaces\r\n24 FastEthernet interfaces\r\n2 Gigabit Ethernet interfaces\r\nThe password-recovery mechanism is enabled.\r\n\r\n512K bytes of flash-simulated non-volatile configuration memory.\r\nBase ethernet MAC Address       : \r\nMotherboard assembly number     : r\nPower supply part number        : \r\nMotherboard serial number       : \r\nPower supply serial number      : \r\nModel revision number           : J0\r\nMotherboard revision number     : A0\r\nModel number                    : \r\nSystem serial number            : \r\nTop Assembly Part Number        : \r\nTop Assembly Revision Number    : B0\r\nVersion ID                      : V05\r\nCLEI Code Number                : \r\nHardware Board Revision Number  : 0x01\r\n\r\n\r\nSwitch Ports Model              SW Version            SW Image                 \r\n------ ----- -----              ----------            ----------               \r\n*    1 26    =       12.2(55)SE11          -M     \r\n\r\n\r\nConfiguration register is 0xF\r\n\r\nHOSTNAME#"
        ]
    }
}

显示运行命令的输出:

代码语言:javascript
复制
TASK [run show commands] ***************************************************************************************************************************************************
changed: [IP]
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-27 11:09:18

在两个任务之间放置这个块,并再次运行它,并使用输出编辑第一个帖子。

代码语言:javascript
复制
 - debug:
     msg: "{{ output }}"

这是可能的:

代码语言:javascript
复制
- copy:
    content: "{{ output.output }}"
    dest: "/home/user/telnettest.txt"

若要在/etc/ansible/ansible.cfg中设置此输出,请使用Ansible 2.5+

代码语言:javascript
复制
stdout_callback = yaml
bin_ansible_callbacks = True
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57672285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档