首页 > 解决方案 > 使用 Ansible nxos_config,我想从 bootflash 中删除一个文件:并发送一个 'y' 但我收到一个错误

问题描述

我想知道您是否可以提供帮助?当我在本地发出命令时,我正在编写一个简单的 Ansible 游戏以从 Nexus 3k 的 bootflash 中删除一个文件:

N3K# del bootflash:1.txt
Do you want to delete "/1.txt" ? (yes/no/abort)   [y] 

因此我在剧本中发送一个“y”

---
- name: Upgrading Nexus
  connection: network_cli
  hosts: n3k
  vars:
    to_delete: '*.txt'
  tasks:
    - name: delete a file
      nxos_config:
        commands: 
          - del bootflash:1.txt
          - echo 'y'

当我运行这个游戏时,我得到:

TASK [delete a file] **********************************************************************************************************************************************************************
task path: /etc/ansible/brrrr.yml:8
<el-cagcc00-01mnl03> ESTABLISH LOCAL CONNECTION FOR USER: root
<el-cagcc00-01mnl03> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-local-25838fJQR1e/ansible-tmp-1573503060.87-17981903721769 `" && echo ansible-tmp-1573503060.87-17981903721769="` echo /root/.ansible/tmp/ansible-local-25838fJQR1e/ansible-tmp-1573503060.87-17981903721769 `" ) && sleep 0'
Using module file /usr/lib/python2.7/site-packages/ansible/modules/network/nxos/nxos_config.py
<el-cagcc00-01mnl03> PUT /root/.ansible/tmp/ansible-local-25838fJQR1e/tmpxuqVCz TO /root/.ansible/tmp/ansible-local-25838fJQR1e/ansible-tmp-1573503060.87-17981903721769/AnsiballZ_nxos_config.py
<el-cagcc00-01mnl03> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-local-25838fJQR1e/ansible-tmp-1573503060.87-17981903721769/ /root/.ansible/tmp/ansible-local-25838fJQR1e/ansible-tmp-1573503060.87-17981903721769/AnsiballZ_nxos_config.py && sleep 0'
<el-cagcc00-01mnl03> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-local-25838fJQR1e/ansible-tmp-1573503060.87-17981903721769/AnsiballZ_nxos_config.py && sleep 0'
<el-cagcc00-01mnl03> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-local-25838fJQR1e/ansible-tmp-1573503060.87-17981903721769/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
WARNING: The below traceback may *not* be related to the actual failure.
  File "/tmp/ansible_nxos_config_payload_i5IR9V/ansible_nxos_config_payload.zip/ansible/module_utils/network/nxos/nxos.py", line 187, in load_config
    resp = connection.edit_config(config, replace=replace)
  File "/tmp/ansible_nxos_config_payload_i5IR9V/ansible_nxos_config_payload.zip/ansible/module_utils/connection.py", line 186, in __rpc__
    raise ConnectionError(to_text(msg, errors='surrogate_then_replace'), code=code)
fatal: [el-cagcc00-01mnl03]: FAILED! => {
    "changed": false, 
    "invocation": {
        "module_args": {
            "after": null, 
            "auth_pass": null, 
            "authorize": null, 
            "backup": false, 
            "backup_options": null, 
            "before": null, 
            "commands": [
                "del bootflash:1.txt", 
                "echo 'y'"
            ], 
            "defaults": false, 
            "diff_against": null, 
            "diff_ignore_lines": null, 
            "host": null, 
            "intended_config": null, 
            "lines": [
                "del bootflash:1.txt", 
                "echo 'y'"
            ], 
            "match": "line", 
            "parents": null, 
            "password": null, 
            "port": null, 
            "provider": null, 
            "replace": "line", 
            "replace_src": null, 
            "running_config": null, 
            "save_when": "never", 
            "src": null, 
            "ssh_keyfile": null, 
            "timeout": null, 
            "transport": null, 
            "use_ssl": null, 
            "username": null, 
            "validate_certs": null
        }
    }, 
    "msg": "timeout value 30 seconds reached while trying to send command: del bootflash:1.txt"
}

PLAY RECAP ********************************************************************************************************************************************************************************
el-cagcc00-01mnl03         : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   

请提前告知Thanx

标签: ansible

解决方案


尝试这个

  tasks:
    - name: delete a file
      nxos_command:
        commands: 
          - delete bootflash:///1.txt no prompt

推荐阅读