ansible批量分發文件含自動備份原文件

目前公司網站前臺有16臺,每次想更新個文件,手動更新真的很讓人抓狂。現在就藉助ansible的copy模塊輕鬆實現批量分發,並自動備份,效果還不錯,拿來分享給大家。

1.前提要安裝好ansible且要與前臺16臺服務器,做好ssh信任,並歸類到一組如v2_51auto_www。

# cat /etc/ansible/hosts

[v1_51auto_www]
172.31.2.68 ansible_ssh_port=22
172.31.2.69 ansible_ssh_port=22
172.31.2.70 ansible_ssh_port=22
172.31.2.71 ansible_ssh_port=22
172.31.2.72 ansible_ssh_port=22
172.16.1.20
172.16.1.21
172.16.1.22
172.16.1.23
172.16.1.24
[v2_51auto_www]
172.16.1.11
172.16.1.12
172.16.1.13
172.16.1.14
172.16.1.19
172.16.1.34

2.把要更新的文件上傳到ansible服務器,我的目錄是/home/maser/upload

[master@localhost upload]$ pwd
/home/master/upload
[master@localhost upload]$ ls
list.jsp  ParamUtils.class  TempUtil.class

3.ansible命令分發

[master@localhost upload]$ ansible v2_51auto_www -s -m copy -a 'src=/home/master/upload/list.jsp dest=/opt/websuite/resin/data/webapps/ROOT/views/car/promotion owner=websuite group=websuite backup=yes'

4.驗證效果

[root@s01 promotion]# ifconfig
eth0      Link encap:Ethernet  HWaddr AE:FC:BB:33:18:41  
          inet addr:172.16.1.11  Bcast:172.16.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:54593130 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42947200 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:141150153477 (131.4 GiB)  TX bytes:114151578105 (106.3 GiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:13401 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13401 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:826668 (807.2 KiB)  TX bytes:826668 (807.2 KiB)

[root@s01 promotion]# pwd
/opt/websuite/resin/data/webapps/ROOT/views/car/promotion
[root@s01 promotion]# ll
總用量 112
-rw-r--r-- 1 websuite websuite 22203 5月  13 14:27 activity.jsp
-rw-r--r-- 1 websuite websuite 42599 5月  20 17:34 list.jsp
-rw-r--r-- 1 root     root     42598 5月  19 17:25 list.jsp.2015-05-20@17:34:12~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章