Операция требует повышения привилегий

У меня проблемы с 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

Playbook:

---
- 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   

Я пытался с подключением: локально, с становлением: включить, но ничего не работает

2 ответа

Похоже, ошибка была поднята заявка: трассировка ios_config на некоторых устройствах

Я использовал следующие изменения в качестве обходного пути:

1. добавить становление в книгу

---

- 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. запустить playbook с параметрами:

    -b

как это:

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

Используйте параметры "-K" и "-b", которые заставят Ansible запросить пароль "СТАТЬ".

Итак, ваша новая командная строка будет:

ansible-playbook roles/Basic_Config/tasks/create_vlan.yml -Kkb -u ansible -vvv

У меня была такая же проблема, но с 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

Другие вопросы по тегам