1

我在使用 ansible 时遇到了麻烦。

我试图创建一些 VLAN,但我得到了这个错误:“操作需要权限提升”

ansible.cfg:

[defaults]

inventory = hosts
host_key_checking = false
gather_facts = false
timeout = 1000

主持人:

[switch]
sw-este ansible_host=192.168.99.10 ansible_network_os=ios

剧本:

---
- name: Crear las VLAN y configurar las interfaces
  hosts: sw-este
  gather_facts: false
  connection: network_cli

  tasks:

  - name: create VLAN
    ios_vlan:
      vlan_id: "{{ item.id }}" 
      name: "{{ item.name }}"
      state: present

    with_items:
      - { id : 21, name : Contabilidad }
      - { id : 23, name : Ingenieria }

这是以下结果:

ansible-playbook 角色/Basic_Config/tasks/create_vlan.yml -k -u ansible -vvv

ansible-playbook 2.5.0
  config file = /root/Training/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]
Using /root/Training/ansible.cfg as config file
SSH password: 
Parsed /root/Training/hosts inventory source with ini plugin

PLAYBOOK: create_vlan.yml ******************************************************
1 plays in roles/Basic_Config/tasks/create_vlan.yml

PLAY [Crear las VLAN y configurar las interfaces] ******************************
META: ran handlers

TASK [create VLAN] *************************************************************
task path: /root/Training/roles/Basic_Config/tasks/create_vlan.yml:9
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/network/ios/ios_vlan.py
<192.168.99.10> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.99.10> EXEC /bin/sh -c 'echo ~ && sleep 0'
<192.168.99.10> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1523359559.78-25490853974926 `" && echo ansible-tmp-1523359559.78-25490853974926="` echo /root/.ansible/tmp/ansible-tmp-1523359559.78-25490853974926 `" ) && sleep 0'
<192.168.99.10> PUT /root/.ansible/tmp/ansible-local-20772YYZlPo/tmplAtgR2 TO /root/.ansible/tmp/ansible-tmp-1523359559.78-25490853974926/ios_vlan.py
<192.168.99.10> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1523359559.78-25490853974926/ /root/.ansible/tmp/ansible-tmp-1523359559.78-25490853974926/ios_vlan.py && sleep 0'
<192.168.99.10> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1523359559.78-25490853974926/ios_vlan.py && sleep 0'
<192.168.99.10> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1523359559.78-25490853974926/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_Mv7Iu8/ansible_module_ios_vlan.py", line 323, in <module>
    main()
  File "/tmp/ansible_Mv7Iu8/ansible_module_ios_vlan.py", line 314, in main
    load_config(module, commands)
  File "/tmp/ansible_Mv7Iu8/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py", line 162, in load_config
  File "/tmp/ansible_Mv7Iu8/ansible_modlib.zip/ansible/module_utils/connection.py", line 146, in __rpc__
ansible.module_utils.connection.ConnectionError: operation requires privilege escalation

failed: [sw-este] (item={u'id': 21, u'name': u'Contabilidad'}) => {
    "changed": false, 
    "item": {
        "id": 21, 
        "name": "Contabilidad"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_Mv7Iu8/ansible_module_ios_vlan.py\", line 323, in <module>\n    main()\n  File \"/tmp/ansible_Mv7Iu8/ansible_module_ios_vlan.py\", line 314, in main\n    load_config(module, commands)\n  File \"/tmp/ansible_Mv7Iu8/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py\", line 162, in load_config\n  File \"/tmp/ansible_Mv7Iu8/ansible_modlib.zip/ansible/module_utils/connection.py\", line 146, in __rpc__\nansible.module_utils.connection.ConnectionError: operation requires privilege escalation\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 1
}
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/network/ios/ios_vlan.py
<192.168.99.10> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.99.10> EXEC /bin/sh -c 'echo ~ && sleep 0'
<192.168.99.10> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1523359560.84-82791789077640 `" && echo ansible-tmp-1523359560.84-82791789077640="` echo /root/.ansible/tmp/ansible-tmp-1523359560.84-82791789077640 `" ) && sleep 0'
<192.168.99.10> PUT /root/.ansible/tmp/ansible-local-20772YYZlPo/tmphTJUVi TO /root/.ansible/tmp/ansible-tmp-1523359560.84-82791789077640/ios_vlan.py
<192.168.99.10> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1523359560.84-82791789077640/ /root/.ansible/tmp/ansible-tmp-1523359560.84-82791789077640/ios_vlan.py && sleep 0'
<192.168.99.10> EXEC /bin/sh -c '/usr/bin/python /root/.ansible/tmp/ansible-tmp-1523359560.84-82791789077640/ios_vlan.py && sleep 0'
<192.168.99.10> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1523359560.84-82791789077640/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_7sSs07/ansible_module_ios_vlan.py", line 323, in <module>
    main()
  File "/tmp/ansible_7sSs07/ansible_module_ios_vlan.py", line 314, in main
    load_config(module, commands)
  File "/tmp/ansible_7sSs07/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py", line 162, in load_config
  File "/tmp/ansible_7sSs07/ansible_modlib.zip/ansible/module_utils/connection.py", line 146, in __rpc__
ansible.module_utils.connection.ConnectionError: operation requires privilege escalation

failed: [sw-este] (item={u'id': 23, u'name': u'Ingenieria'}) => {
    "changed": false, 
    "item": {
        "id": 23, 
        "name": "Ingenieria"
    }, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_7sSs07/ansible_module_ios_vlan.py\", line 323, in <module>\n    main()\n  File \"/tmp/ansible_7sSs07/ansible_module_ios_vlan.py\", line 314, in main\n    load_config(module, commands)\n  File \"/tmp/ansible_7sSs07/ansible_modlib.zip/ansible/module_utils/network/ios/ios.py\", line 162, in load_config\n  File \"/tmp/ansible_7sSs07/ansible_modlib.zip/ansible/module_utils/connection.py\", line 146, in __rpc__\nansible.module_utils.connection.ConnectionError: operation requires privilege escalation\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 1
}
    to retry, use: --limit @/root/Training/roles/Basic_Config/tasks/create_vlan.retry

PLAY RECAP *********************************************************************
sw-este                    : ok=0    changed=0    unreachable=0    failed=1   

我尝试使用连接:本地,使用 become_method:启用但没有任何效果

4

3 回答 3

2

看起来错误已被提出票证:ios_config traceback on some devices

我遵循以下更改作为解决方法:

1.在playbook中添加become_method

---

- name: Network Getting Started First Playbook Extended
  connection: network_cli
  become_method: enable
  hosts: all
  tasks:
    - name: Update the hostname
      ios_config:
        lines:
          - hostname ansible-changed
        backup: no
  1. 运行带有参数的剧本:

    -b

    -K

像这样:

ansible-playbook -i 192.168.1.100, -u 测试 -k -b -K -e ansible_network_os=ios first_playbook_ext.yml

于 2018-08-21T06:47:02.550 回答
0

使用“-K”和“-b”选项,这将导致 Ansible 提示您输入“成为”密码。

所以你的新命令行将是:

ansible-playbook roles/Basic_Config/tasks/create_vlan.yml -Kkb -u ansible -vvv
于 2020-05-29T17:54:19.973 回答
0

我遇到了同样的问题,但使用的是 Ansible 2.5.3 版。

修复是降级到 2.5.2。

如果你在 Ubuntu 上,你可以从这里得到它: https ://launchpad.net/~ansible/+archive/ubuntu/ansible/+packages?field.name_filter=&field.status_filter=&field.series_filter=

$ sudo dpkg -i ansible_2.5.2-1ppa_xenial_all.deb 

https://fossies.org/diffs/ansible/2.5.2_vs_2.5.3/index.html

于 2018-05-23T16:24:52.240 回答