我在使用 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:启用但没有任何效果