ansible ssh could not resolve hostname报错

最近ansible升级到2.3版本后,使用ansible过程中,部分job会执行失败,报错如下:

[email protected] | UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname x.x.x.x]: Name or service not known\r\nCouldn't read packet: Connection reset by peer\r\n", 
    "unreachable": true
}

后通过google(百度真不行),在stack overflow找到了答案,原帖链接:

https://stackoverflow.com/questions/33386890/why-giving-a-host-alias-does-not-work-with-an-ansible-inventory-file/33387754#33387754

解释下,之前一直使用的是ansible1.x版本的,普遍使用的用户也是web用户,但是有几台机器是指定用root执行的,所以ansible hosts里有几个[email protected]

但是到了ansible2的版本不认了,必须写成

x.x.x.x  ansible_user=root

这样的形式才行

特此留档

发表评论

电子邮件地址不会被公开。 必填项已用*标注

This blog is kept spam free by WP-SpamFree.