Ansible安装及简单应用
1、名称解析# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.20 stu
192.168.0.21 node1
192.168.0.22 node2
192.168.0.23 node3
2、建立互信
# ssh-keygen -t rsa-P ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
5e:b9:38:77:4f:d9:e9:ae:94:cd:29:4b:c5:0f:1a:2b root@stu
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| |
| ..|
| S o . .o |
| . o . +=++|
| + E +=o=o|
| o ooo+|
| o+o |
+-----------------+
# ssh-copy-id -i .ssh/id_rsa.pub root@node1
# ssh-copy-id -i .ssh/id_rsa.pub root@node2
# ssh-copy-id -i .ssh/id_rsa.pub root@node3
3、定义主机组
# vim /etc/ansible/hosts
:.,$s/^\([^[:space:]#]\)/#\1/g #所有以非空白字符或#开头的行都加上注释
node1
node2
node2
node3
页:
[1]