HuaweiSwitch / CloudEngine-Ansible

Ansible modules to automate HUAWEI CloudEngine switches
GNU General Public License v3.0
143 stars 51 forks source link

Socket error #15

Closed Nukete closed 7 years ago

Nukete commented 7 years ago

Hi,

following this guide install is ok: CloudEngine-Huawei when trying to execute command as follows: (Using default command in example)

ssh to switch granted and tested through radius user

root@localhost:~# ansible -m ce_command -a "commands='display vlan summary' transport='cli' host=10.100.1.29 port=22 username=blabla password=blabla" localhost --connection local

adaroma@nnoc:~/CloudEngine-Ansible$ ansible -m ce_command -a "commands='display vlan summary' transport='cli' host=10.100.1.29 port=22 username=blabla password=blabla" localhost --connection local -vvv
Using /etc/ansible/ansible.cfg as config file
 [WARNING]: provided hosts list is empty, only localhost is available

META: ran handlers
Using module file /home/adaroma/CloudEngine-Ansible/library/ce_command.py
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: adaroma
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1497529426.59-123144021550665 `" && echo ansible-tmp-1497529426.59-123144021550665="` echo $HOME/.ansible/tmp/ansible-tmp-1497529426.59-123144021550665 `" ) && sleep 0'
<127.0.0.1> PUT /tmp/tmp3WuXWv TO /home/adaroma/.ansible/tmp/ansible-tmp-1497529426.59-123144021550665/ce_command.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/adaroma/.ansible/tmp/ansible-tmp-1497529426.59-123144021550665/ /home/adaroma/.ansible/tmp/ansible-tmp-1497529426.59-123144021550665/ce_command.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python /home/adaroma/.ansible/tmp/ansible-tmp-1497529426.59-123144021550665/ce_command.py; rm -rf "/home/adaroma/.ansible/tmp/ansible-tmp-1497529426.59-123144021550665/" > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_6kOfzf/ansible_module_ce_command.py", line 264, in <module>
    main()
  File "/tmp/ansible_6kOfzf/ansible_module_ce_command.py", line 235, in main
    responses = run_commands(module, commands)
  File "/tmp/ansible_6kOfzf/ansible_modlib.zip/ansible/module_utils/ce.py", line 232, in run_commands
  File "/tmp/ansible_6kOfzf/ansible_modlib.zip/ansible/module_utils/ce.py", line 149, in run_commands
  File "/tmp/ansible_6kOfzf/ansible_modlib.zip/ansible/module_utils/ce.py", line 116, in exec_command
  File "/tmp/ansible_6kOfzf/ansible_modlib.zip/ansible/module_utils/connection.py", line 60, in exec_command
  *File "/usr/lib/python2.7/socket.py", line 224, in meth
    return getattr(self._sock,name)(*args)
TypeError: argument must be string or read-only character buffer, not None*

localhost | FAILED! => {
    "changed": false, 
    "failed": true, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_6kOfzf/ansible_module_ce_command.py\", line 264, in <module>\n    main()\n  File \"/tmp/ansible_6kOfzf/ansible_module_ce_command.py\", line 235, in main\n    responses = run_commands(module, commands)\n  File \"/tmp/ansible_6kOfzf/ansible_modlib.zip/ansible/module_utils/ce.py\", line 232, in run_commands\n  File \"/tmp/ansible_6kOfzf/ansible_modlib.zip/ansible/module_utils/ce.py\", line 149, in run_commands\n  File \"/tmp/ansible_6kOfzf/ansible_modlib.zip/ansible/module_utils/ce.py\", line 116, in exec_command\n  File \"/tmp/ansible_6kOfzf/ansible_modlib.zip/ansible/module_utils/connection.py\", line 60, in exec_command\n  File \"/usr/lib/python2.7/socket.py\", line 224, in meth\n    return getattr(self._sock,name)(*args)\nTypeError: argument must be string or read-only character buffer, not None\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE", 
    "rc": 0
}

FYI:

ansible --version
ansible 2.3.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/usr/local/lib/python2.7/dist-packages/ansible/modules/']
  python version = 2.7.3 (default, Jun 21 2016, 18:38:19) [GCC 4.7.2]
QijunPan commented 7 years ago
  1. which CloudEngine branch or releases did you used? ansible 2.3.x: https://github.com/HuaweiSwitch/CloudEngine-Ansible/tree/devel-2.3 ansible 2.2.x: https://github.com/HuaweiSwitch/CloudEngine-Ansible/tree/devel-2.2 ansbile 2.4.x: No additional installation is required, and the Cloudengine modules already contains.

  2. Can SSH login switch?

    ssh username@xxx.xxx.xxx -p sshport
  3. ansible 2.2 and 2.3 install way is defferent, you can install it by this script on Ubunbu or manually run step by step on other platforms, according to this script:

ansible 2.3.x: https://github.com/HuaweiSwitch/CloudEngine-Ansible/blob/devel-2.3/install.sh

  1. check constants.py is already configured
    $ANSIBLE_PATH/constants.py

    ce must add on macro NETWORK_GROUP_MODULES, just like: https://github.com/HuaweiSwitch/CloudEngine-Ansible/blob/devel-2.3/constants.py

    NETWORK_GROUP_MODULES          = get_config(p, DEFAULTS, 'network_group_modules','NETWORK_GROUP_MODULES', ['eos', 'nxos', 'ios', 'iosxr', 'junos', 'ce',
                                                                                                           'vyos', 'sros', 'dellos9', 'dellos10', 'dellos6'],
Nukete commented 7 years ago

Hello,

thanks for your support

Finally I managed to solve problem: 1.- I deployed a new fresh Ansible install

adaroma@adaroma-PC:~/CloudEngine-Ansible$ ansible --version ansible 2.3.1.0 config file = /etc/ansible/ansible.cfg configured module search path = Default w/o overrides python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

2.- Used script to install CloudEngine modules (thanks for clarification in previous post :+1:): https://github.com/HuaweiSwitch/CloudEngine-Ansible/blob/devel-2.3/install.sh

3.- Just for reference: I've found another problem related to paramiko func:

2017-06-16 12:43:17,658 paramiko.transport Unknown exception: Use module Crypto.Signature.pkcs1_15 instead

192.168.3.120 | FAILED! => { "changed": false, "failed": true, "msg": "unable to open shell. Please see: https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell", "rc": 255 My previous paramiko version: paramiko-1.16.0 I've upgraded it to paramiko-2.2.1 and all is ok:

192.168.3.120 | SUCCESS => { "changed": false, "stdout": [ "Static vlan:\nTotal 3 static vlan.\n 1 54 705 \n\nDynamic vlan:\nTotal 0 dynamic vlan.\n\nReserved vlan:\nTotal 0 reserved vlan." ], "stdout_lines": [ [ "Static vlan:", "Total 3 static vlan.", " 1 54 705 ", "", "Dynamic vlan:", "Total 0 dynamic vlan.", "", "Reserved vlan:", "Total 0 reserved vlan." ] ]

QijunPan commented 7 years ago

OK, have a nice day!