使用Ansible nxos_config,我想从bootflash中删除文件:并发送“ y”,但出现错误

时间:2019-11-11 20:18:30

标签: ansible

我想知道您能否协助您? 我正在编写一个简单的Ansible剧本,以从Nexus 3k的启动闪存中删除文件 当我在本地发出命令时:

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   

请告知 提前感谢

1 个答案:

答案 0 :(得分:0)

尝试一下

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