【问题标题】:basic telnet script to copy to flash drive复制到闪存驱动器的基本 telnet 脚本
【发布时间】:2019-02-12 15:22:21
【问题描述】:

我正在尝试使用 ansible 远程登录到 cisco 交换机并应用 copy startup-config disk0 命令。

Ansible 似乎永远无法通过 (?i)"Destination filename": "work please" 通过 expect 命令

    ---
    - hosts: all
      gather_facts: false
      connection: local
      tasks:
      - name: telnet,login and execute command
        ignore_errors: true
        expect:
        command: telnet "{{ inventory_hostname }}"
        responses:
          (?i)password: "{{ password}}"
          (?i)#: copy startup-config disk0
          (?i)"Destination filename": "{{ lookup('pipe','date') }"
        echo: yes
      register: telnet_output

我得到了什么输出

ansible-playbook 2.7.6

配置文件 = /etc/ansible/ansible.cfg 配置的模块搜索路径 = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python模块位置= /usr/lib/python2.7/site-packages/ansible 可执行位置 = /usr/bin/ansible-playbook python 版本 = 2.7.5(默认,2018 年 10 月 30 日,23:45:53)[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] 使用 /etc/ansible/ansible.cfg 作为配置文件 /var/lib/awx/projects/6500/hosts 不符合 host_list 要求,如果这是意外情况,请检查插件文档 /var/lib/awx/projects/6500/hosts 不符合脚本要求,如果这是意外情况,请检查插件文档

剧本:copy-startup.yml **************************************** ****************************************************** ****************************************************** ****************************************************** *************** 1 次在 copy-startup.yml 中播放

播放 [全部] ******************************************* ****************************************************** ****************************************************** ****************************************************** ****************************** META:运行处理程序

TASK [telnet,登录并执行命令] ****************************************** ****************************************************** ****************************************************** ****************************************************** **** 任务路径:/var/lib/awx/projects/6500/copy-startup.yml:6 致命:[66.90.19.18]:失败! => {“更改”:true,“cmd”:“telnet \”66.90.19.18\“”,“delta”:“0:00:30.370396”,“end”:“2019-02-12 10:09: 41.473716”、“msg”:“命令超时”、“rc”:null、“start”:“2019-02-12 10:09:11.103320”、“stdout”:“正在尝试 66.90.19.18...\r \r\n已连接到 66.90.19.18。\r\r\n转义字符为 '^]'。\r\r\n\r\n\r\n用户访问验证\r\n\r\n密码: \r\ nLAB-6500-SUP2T#copy startup-config disk0\r\nDestination filename [disk0]? ", "stdout_lines": ["Trying 66.90.19.18...", "", "Connected to 66.90.19.18.", " ", "转义字符是'^]'。", "", "", "", "用户访问验证", "", "密码: ", "LAB-6500-SUP2T#copy startup-config disk0", "目标文件名 [disk0]?"]} ...忽略

播放回顾 ************************************************ ****************************************************** ****************************************************** ****************************************************** ****************************** 66.90.19.18 : ok=2 changed=1 unreachable=0 failed=0

似乎永远不想写目标文件名[disk0]? 任何想法

【问题讨论】:

  • 你有什么问题?
  • 我怎样才能忽略 (?i)"Destination filename": "work please" 它似乎永远不会工作。

标签: ansible backup telnet cisco


【解决方案1】:

(?i)"Destination filename" 匹配带双引号的字符串。

你需要:

responses:
    '(?i)password': "{{ password}}"
    '(?i)#': copy startup-config disk0
    '(?i)Destination filename': "{{ lookup('pipe','date') }"

【讨论】:

    【解决方案2】:
       ---
       - hosts: '6500'
       gather_facts: true
       connection: local
       tasks:
    
       - name: telnet,login and execute command
         ignore_errors: true
         expect:
            command: telnet "{{ inventory_hostname }}"
            responses:
              (?i)Password: {{ password }}
             (?i)Destination filename [disk0]? : "{{ lookup('pipe','date +%Y-%m-%d-%H-%M') }} {{ inventory_hostname }}"
             (?i)#: copy startup-config disk0
             (?i){{COMMAND}}: exit
           echo: yes
          register: telnet_output
    

    这似乎是我需要的最佳解决方案。我改变了操作顺序,它在摇摆,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-06
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      相关资源
      最近更新 更多