使用Ansible删除整个公司网络设备上的旧用户名

时间:2018-12-13 17:41:27

标签: ansible cisco

针对测试开关创建了以下测试yml文件,以明确配置,以下错误。我在最后一个任务中定义了提供者,也没有运气

---
  - hosts: aus2-mdf-testswitches
  gather_facts: no
  connection: local

  tasks:
  - name: OBTAIN LOGIN CREDENTIALS
    include_vars: secret.yml

  - name: DEFINE PROVIDER
    set_fact:
      provider:
        host: "{{ inventory_hostname }}"
        username: "{{ creds['username'] }}"
        password: "{{ creds['password'] }}"
        auth_pass: "{{ creds['auth_pass'] }}"

  - name: Delete users with aggregate
    ios_user:
     aggregate:
       - name: chase
     state: absent

出现的错误。请记住,我是新手,这个问题对于这个小组可能非常容易,但是我非常感谢。仅供参考,请阅读https://docs.ansible.com/ansible/2.4/ios_user_module.html

[ansible@dc1netansible automation]$ ansible-playbook -i inventories/prod/hosts playbooks/deleteUsername.yml

PLAY [aus2-mdf-testswitches] ********************************************************************************************************************************************

TASK [OBTAIN LOGIN CREDENTIALS] *****************************************************************************************************************************************
ok: [aus2-mdf-testsw1]
ok: [aus2-mdf-testsw2]

TASK [DEFINE PROVIDER] **************************************************************************************************************************************************
ok: [aus2-mdf-testsw1]
ok: [aus2-mdf-testsw2]

TASK [Delete users with aggregate] **************************************************************************************************************************************
fatal: [aus2-mdf-testsw1]: FAILED! => {"changed": false, "msg": "unable to open shell. Please see: https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell"}
fatal: [aus2-mdf-testsw2]: FAILED! => {"changed": false, "msg": "unable to open shell. Please see: https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell"}
        to retry, use: --limit @/home/ansible/automation/playbooks/deleteUsername.retry

PLAY RECAP **************************************************************************************************************************************************************
aus2-mdf-testsw1           : ok=2    changed=0    unreachable=0    failed=1   
aus2-mdf-testsw2           : ok=2    changed=0    unreachable=0    failed=1

****使用新的yml配置更新了错误****

  ---
- hosts: aus2-mdf-testswitches
  gather_facts: no
  connection: local

  tasks:
  - name: OBTAIN LOGIN CREDENTIALS
    include_vars: secret.yml

  - name: DEFINE PROVIDER
    set_fact:
      provider:
        host: "{{ inventory_hostname }}"
        username: "{{ creds['username'] }}"
        password: "{{ creds['password'] }}"
        auth_pass: "{{ creds['auth_pass'] }}"

  - name: Delete users with aggregate
    ios_user:
      users:
        - name: chase
      authorize: yes
      provider: "{{ provider }}"
      state: absent
    register: result 


[ansible@dc1netansible automation]$ ansible-playbook -i inventories/prod/hosts playbooks/deleteUsername.yml

PLAY [aus2-mdf-testswitches] ********************************************************************************************************************************************

TASK [OBTAIN LOGIN CREDENTIALS] *****************************************************************************************************************************************
ok: [aus2-mdf-testsw1]
ok: [aus2-mdf-testsw2]

TASK [DEFINE PROVIDER] **************************************************************************************************************************************************
ok: [aus2-mdf-testsw1]
ok: [aus2-mdf-testsw2]

TASK [Delete users with aggregate] **************************************************************************************************************************************
fatal: [aus2-mdf-testsw1]: FAILED! => {"changed": false, "msg": "unable to open shell. Please see: https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell"}
fatal: [aus2-mdf-testsw2]: FAILED! => {"changed": false, "msg": "unable to open shell. Please see: https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell"}
        to retry, use: --limit @/home/ansible/automation/playbooks/deleteUsername.retry

PLAY RECAP **************************************************************************************************************************************************************
aus2-mdf-testsw1           : ok=2    changed=0    unreachable=0    failed=1   
aus2-mdf-testsw2           : ok=2    changed=0    unreachable=0    failed=1

可能是我的IOS版本过旧,因为我在Cisco交换机上使用12倍速火车。 Ansible提到这是在15倍速火车上测试的。

****最新更新****

PLAY [aus2-mdf-testswitches] ********************************************************************************************************************************************

TASK [OBTAIN LOGIN CREDENTIALS] *****************************************************************************************************************************************
ok: [aus2-mdf-testsw1]
ok: [aus2-mdf-testsw2]

TASK [DEFINE PROVIDER] **************************************************************************************************************************************************
ok: [aus2-mdf-testsw1]
ok: [aus2-mdf-testsw2]

TASK [Delete users with aggregate] **************************************************************************************************************************************
fatal: [aus2-mdf-testsw2]: FAILED! => {"changed": false, "msg": "unable to retrieve current config", "stderr": "show running-config | section username\r\n                                       ^\r\n% Invalid input detected at '^' marker.\r\n\r\naus2-mdf-testsw2#", "stderr_lines": ["show running-config | section username", "                                       ^", "% Invalid input detected at '^' marker.", "", "aus2-mdf-testsw2#"]}
fatal: [aus2-mdf-testsw1]: FAILED! => {"changed": false, "msg": "unable to retrieve current config", "stderr": "show running-config | section username\r\n                                       ^\r\n% Invalid input detected at '^' marker.\r\n\r\naus2-mdf-testsw1#", "stderr_lines": ["show running-config | section username", "                                       ^", "% Invalid input detected at '^' marker.", "", "aus2-mdf-testsw1#"]}
        to retry, use: --limit @/home/ansible/automation/playbooks/deleteUsername.retry

此处列出的配置在我的Cisco交换机上的IOS上不起作用。

0 个答案:

没有答案