Centos7.5 ansible执行命令报错
问题:
[root@m01 ~]# ansible servers -a "hostname"
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit
localhost does not match 'all'
[WARNING]: Could not match supplied host pattern, ignoring: servers
原因:
没有添加主机清单
解决方法:
方式一:
[root@m01 ~]# vim /etc/ansible/hosts
[webservers]
172.16.1.7
[mysqlservers]
172.16.1.8
[servers:children]
webservers
mysqlservers
[root@m01 ~]# ansible servers -a "hostname"
172.16.1.8 | CHANGED | rc=0 >>
web02
172.16.1.7 | CHANGED | rc=0 >>
web01
方式二:
[root@m01 ~]# vim hosts
[webservers]
172.16.1.7
[mysqlservers]
172.16.1.8
[servers:children]
webservers
mysqlservers
[root@m01 ~]# ansible servers -a "hostname" -i ./hosts
172.16.1.8 | CHANGED | rc=0 >>
web02
172.16.1.7 | CHANGED | rc=0 >>
web01