微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ansible Networks 错误“操作需要提权”

如何解决Ansible Networks 错误“操作需要提权”

我正在关注 youtube 上的基本 Ansible 网络工程师演示,但出现以下错误


ubuntu@DESKTOP-P91I0V3:~/Ansible/Networking$ ansible-playbook ansible-router\ play2.yml -v 使用 /etc/ansible/ansible.cfg 作为配置文件

PLAY [Danny 的通用路由器配置] **************************************** ****************************************************** *****

TASK [全局配置设置]******************************************** ****************************************************** ****************** 致命:[R1]:失败! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"},"changed": false,"msg": "操作需要提权"}

播放回顾************************************************ ****************************************************** ************************************ R1 : ok=0 已更改=0 无法访问=0 失败=1 已跳过=0 已获救=0 已忽略=0


我的剧本是这样的:


- name: Danny's Generic Router Configuration
  hosts: R1
  gather_facts: false
  connection: local

  vars:
    cli:
      username: admin
      password: cisco
      timeout: 100

  tasks:
    - name: Global config settings
      ios_config:

    provider: "{{ cli }}"
    lines:
      - ipv6 unicast-routing
      - errdisable recovery interval 60
      - security passwords min-length 5
      - ip name-server 99.99.99.99
      - no ip http server
      - ip http secure-server
      - snmp-server community ipvzero1 RO
      - snmp-server community ipvzero2 RW
      - ntp server 99.99.99.99
      - banner motd &**********THIS IS Danny'S ROUTER - DO NOT MAKE CHANGES UNLESS AUTHORISED! YOU WILL BE PROSECUTED! **********&

  register: print_output

-  debug: var=print_output

我的配置文件如下所示:


[defaults]
inventory = ./hosts
#host_key_checking = false
timeout = 60

无论有没有“host_key_checking”我都厌倦了 我在 Stack Overflow 中看到其他人也有类似的问题,但没有任何东西能最终解决我的问题。

我可以从我的 WSL2 Ubuntu 环境通过 SSH 连接到 R1。

谁能帮我解决这个“操作需要提权”的问题吗?

解决方法

明白了! 很多人建议使用“成为”方法,但在我的情况下不起作用。 对我来说修复只有 2 行,可以在 Ansible 文档中找到: https://docs.ansible.com/ansible/latest/collections/cisco/ios/ios_config_module.html


  vars:
    cli:
      username: admin
      password: cisco
      timeout: 100
      auth_pass: cisco

  tasks:
    - name: Global config settings
      ios_config:
        provider: "{{ cli }}"
        authorize: yes
        lines: 

有效的 2 行是:

auth_pass:思科

授权:是

我希望这能在未来对其他人有所帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。