我遇到了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 roles / 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
我尝试使用connection:local,使用become_method:enable但没有任何工作
答案 0 :(得分: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
答案 1 :(得分:0)
好像该错误已被提出:ios_config traceback on some devices
我遵循以下更改作为解决方法:
1.add剧本中的成为方法
---
- 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
使用以下参数运行剧本:
-b
-K
像这样:
ansible-playbook -i 192.168.1.100,-u test -k -b -K -e ansible_network_os = ios first_playbook_ext.yml
答案 2 :(得分:0)
使用“ -K”和“ -b”选项,这将使Ansible提示您输入“ BECOME”密码。
因此您的新命令行将是:
ansible-playbook roles/Basic_Config/tasks/create_vlan.yml -Kkb -u ansible -vvv