1)方式一:
#ip+端口+用户+密码 [root@m01 ~]# vim /etc/ansible/hosts [web01] 172.16.1.7 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1' [web03] 172.16.1.7 ansible_ssh_port=22 #测试主机清单 [root@m01 ~]# ansible '*' -m ping
2)方式二
[root@m01 ~]# vim /etc/hosts 172.16.1.7 web01 172.16.1.9 web03 [root@m01 ~]# vim /etc/ansible/hosts [web01] web01 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1' [web03] web03 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'
3)方式三
[root@m01 ~]# vim /etc/ansible/hosts [web1] web01 [web3] web03 [web1:vars] ansible_ssh_pass='1' [web3:vars] ansible_ssh_pass='1'
4)基于秘钥的方式
#生成密钥对 [root@m01 ~]# ssh-keygen #推送秘钥 [root@m01 ~]# ssh-copy-id 172.16.1.7 [root@m01 ~]# ssh-copy-id 172.16.1.9 #配置 [root@m01 ~]# vim /etc/ansible/hosts [web1] web01 [web3] web03
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。