修改了/etc/ansible/hosts中的配置,把IP地址换成了hostname
如下:
[bendi]
#192.168.88.130
OracleLinux
#192.168.88.131
suse11
在直接对单个客户机进行操作时,报错如下:
[root@redhat7 ~]# ansible OralceLinux -m shell -a "df -h"
[WARNING]: Could not match supplied host pattern, ignoring: 192.168.88.131
[WARNING]: No hosts matched, nothing to do
此时,我以bendi组作为操作对象,如下:
ansible bendi -m shell -a "df -h"
The authenticity of host 'suse11 (192.168.88.131)' can't be established.
RSA key fingerprint is f8:48:58:91:c0:31:77:c4:47:73:30:9a:e0:55:28:92.
Are you sure you want to continue connecting (yes/no)? The authenticity of host 'oraclelinux (192.168.88.130)' can't be established.
ECDSA key fingerprint is bf:af:28:c9:4c:05:c3:ed:3c:76:9d:83:17:91:be:f0.
Are you sure you want to continue connecting (yes/no)? yes
需要手工yes两下才重新建立了连接。
suse11 | SUCCESS | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 29G 14G 13G 52% /
devtmpfs 998M 104K 997M 1% /dev
tmpfs 998M 88K 997M 1% /dev/shm
yes
OracleLinux | SUCCESS | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
devtmpfs 845M 0 845M 0% /dev
tmpfs 863M 0 863M 0% /dev/shm
tmpfs 863M 9.3M 854M 2% /run
tmpfs 863M 0 863M 0% /sys/fs/cgroup
/dev/sda2 30G 24G 7.0G 77% /
tmpfs 173M 12K 173M 1% /run/user/42
tmpfs 173M 0 173M 0% /run/user/0
之后,在对两个客户机分别进行单独操作时,就不会再说找不到匹配的主机名了。
[root@redhat7 ~]# ansible suse11 -m shell -a "df -h"
suse11 | SUCCESS | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 29G 14G 13G 52% /
devtmpfs 998M 104K 997M 1% /dev
tmpfs 998M 88K 997M 1% /dev/shm
[root@redhat7 ~]# ansible OracleLinux -m shell -a "df -h"
OracleLinux | SUCCESS | rc=0 >>
Filesystem Size Used Avail Use% Mounted on
devtmpfs 845M 0 845M 0% /dev
tmpfs 863M 0 863M 0% /dev/shm
tmpfs 863M 9.3M 854M 2% /run
tmpfs 863M 0 863M 0% /sys/fs/cgroup
/dev/sda2 30G 24G 7.0G 77% /
tmpfs 173M 12K 173M 1% /run/user/42
tmpfs 173M 0 173M 0% /run/user/0
问题得以解决。