default ansible template returns error

2019-09-20 16:13发布

问题:

do Ansible in default configuration works with other vendors? For example Huawei ?

If i'm running some testing commands like:

sudo ansible -m shell -a 'display version' servers

10.46.1.1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: \r\n**********************************************************************\r\n* Jus esate prisijunge prie privacios irangos. Visi veiksmai,vykdomi *\r\n* su sia iranga, yra fiksuojami. Tam, kad prieiti prie sios irangos  *\r\n* ir (ar) atlikti irangos konfiguracija ar kitus veiksmus, jus turite*\r\n* tureti atitinkama leidima.                                         *\r\n* Uz neteiseta prisijungima bei neteisetus veiksmus su iranga taikoma*\r\n* istatymuose numatyta atsakomybe,iskaitant ir baudziamaja atsakomybe*\r\n* Prasome  atsijungti.Jeigu  jus esate   autorizuotas  vartotojas,   *\r\n* prisijungdamas, jus atsakote uz teisingai atlikta konfiguracija ir *\r\n* kitus savo vardu atliktus veiksmus.                                *\r\n**********************************************************************\r\n* You are connected to private equipment. All the actions performed  *\r\n* with the equipment are recorded. In order to access this equipment *\r\n* and (or) perform its configuration or other  actions, you must have*\r\n* an appropriate permission. Illegal connection and illegal actions  *\r\n* with the equipment.                                                *\r\n* Will be subject to liability, including criminal liability, as     *\r\n* provided for in the laws of the Republic of Lithuania. Please      *\r\n* disconnect immediately. If you are an authorized user, by          *\r\n* connecting  to the equipment, you assume liability for performing  *\r\n* correct configuration and other actions under your behalf.         *\r\n**********************************************************************\r\nUser Authentication\r\npacket_write_wait: Connection to 10.46.1.1 port 22: Broken pipe\r\n",
    "unreachable": true
}

or

osboxes@osboxes:~$ sudo ansible -m ping servers

10.46.1.1 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: \r\n**********************************************************************\r\n* Jus esate prisijunge prie privacios irangos. Visi veiksmai,vykdomi *\r\n* su sia iranga, yra fiksuojami. Tam, kad prieiti prie sios irangos  *\r\n* ir (ar) atlikti irangos konfiguracija ar kitus veiksmus, jus turite*\r\n* tureti atitinkama leidima.                                         *\r\n* Uz neteiseta prisijungima bei neteisetus veiksmus su iranga taikoma*\r\n* istatymuose numatyta atsakomybe,iskaitant ir baudziamaja atsakomybe*\r\n* Prasome  atsijungti.Jeigu  jus esate   autorizuotas  vartotojas,   *\r\n* prisijungdamas, jus atsakote uz teisingai atlikta konfiguracija ir *\r\n* kitus savo vardu atliktus veiksmus.                                *\r\n**********************************************************************\r\n* You are connected to private equipment. All the actions performed  *\r\n* with the equipment are recorded. In order to access this equipment *\r\n* and (or) perform its configuration or other  actions, you must have*\r\n* an appropriate permission. Illegal connection and illegal actions  *\r\n* with the equipment.                                                *\r\n* Will be subject to liability, including criminal liability, as     *\r\n* provided for in the laws of the Republic of Lithuania. Please      *\r\n* disconnect immediately. If you are an authorized user, by          *\r\n* connecting  to the equipment, you assume liability for performing  *\r\n* correct configuration and other actions under your behalf.         *\r\n**********************************************************************\r\nUser Authentication\r\nchannel_by_id: 2: bad id: channel free\r\nDisconnecting: Received data for nonexistent channel 2.\r\n",
    "unreachable": true
}

it just connects and immediatly disconnects without entering any command, like "display version". Could it be because im running it not on Cisco device, but on other vendor ? Maybe some special modules ir required ?

Thanks

回答1:

Have you confirmed you can connect to those machines normally via ssh? Have you created an ansible account on the machines your trying to connect to? It sounds like the user account that is trying to run ansible on your host, perhaps doesn't have an ssh key on the host. Have you tried

ssh-copy-id ansible@host

and confirmed you can log into that host

ssh ansible@host

with the key?



回答2:

You can use other module different from 'shell' to access Huawei equipaments. If you look here you will see some Cloud Engine modules. Shell module is for servers, not for switches.

So, I'll would write something like this: ansible -m ce_command -a 'display version' servers