要复制到闪存驱动器的基本telnet脚本

问题描述 投票:-1回答:2

我试图使用ansible telnet到cisco开关并应用copy startup-config disk0命令。

Ansible似乎永远无法通过expect命令传递(?i)“目标文件名”:“请工作”

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

config file = /etc/ansible/ansible.cfg配置模块搜索路径= [u'/ root / .ansible / plugins / modules',u'/ usr / share / ansible / plugins / modules'] ansible python module location = / usr / lib / python2.7 / site-packages / ansible executable location = / usr / bin / ansible-playbook python version = 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:跑来跑去

任务[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 \ n \ r \ n连接到66.90.19.18。\ r \ n \ n \ n \ nEscape字符为'^]'。\ r \ n \ 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。“,” “,”Escape字符为'^]'。“,”“,”“,”“,”用户访问验证“,”“,”密码:“,”LAB-6500-SUP2T#copy startup-config disk0“, “目标文件名[disk0]?”]} ...忽略

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

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

ansible backup telnet cisco
2个回答
0
投票

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

你需要:

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

0
投票
   ---
   - 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

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

© www.soinside.com 2019 - 2024. All rights reserved.