[iyunv@master ~]# ssh-keygen -t rsa -P '' 生成一对密钥
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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:
dc:a5:7d:fc:ff:42:8c:8a:55:38:73:87:35:9a:f5:6a root@CentOS
The key's randomart image is:
+--[ RSA 2048]----+
| |
| + |
| ..* o |
| . .++*.. .|
| S o=.+o. |
| . ..E. |
| o . o .|
| . . . .|
| .+|
+-----------------+
[iyunv@master ~]# ansible web -a 'ntpdate 202.118.1.81'
192.168.1.130 | success | rc=0 >>
18 Nov 22:50:54 ntpdate[21487]: step time server 202.118.1.81 offset 1.531700 sec
192.168.1.120 | success | rc=0 >>
18 Nov 22:50:54 ntpdate[13616]: adjust time server 202.118.1.81 offset 0.313219 sec
将时间更新写入cron
[iyunv@master ~]# ansible all -m cron -a 'name="sync time" minute="*/5" job="/usr/sbin/ntpdate 202.118.1.81 &> /dev/null"'
192.168.1.130 | success >> {
"changed": true,
"jobs": [
"sync time"
]
}
[iyunv@master~]# ansible web -m yum -a 'name=httpd state=present'
[iyunv@master ~]# ansible web -a 'service httpd start'
192.168.1.130 | success | rc=0 >>
Starting httpd: [ OK ]httpd: apr_sockaddr_info_get() failed for CentOS
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
192.168.1.120 | success | rc=0 >>
Starting httpd: [ OK ]httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[iyunv@master ~]# touch index.html
[iyunv@master ~]# echo heartbeatV2 > index.html
[iyunv@master ~]# scp index.html root@192.168.1.130:/var/www/html/
index.html 100% 16 0.0KB/s 00:00
[iyunv@master ~]# scp index.html root@192.168.1.120:/var/www/html/
index.html 100% 16 0.0KB/s 00:00
验证httpd是否安装成功
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@master ~]# ansible master -a 'curl 192.168.1.{120,130}'
192.168.1.150 | success | rc=0 >>
--_curl_--192.168.1.120
heartbeatV2
--_curl_--192.168.1.130
heartbeatV2
[1/2]: 192.168.1.120 -->
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 16 0 16 0 0 5072 0 --:--:-- --:--:-- --:--:-- 8000