一键部署rsync服务
[root@m01 conf]# cat /server/scripts/rsync.yaml
# command playbook
- hosts: 172.16.1.41
tasks:
- name: setup01:install rsync
yum:
name: rsync
state: installed
- name: setup02:edit rsync conf file
copy:
src: /etc/ansible/conf/rsyncd.conf
dest: /etc/
- name: setup03:create rsync user
user:
name: rsync
state: present
create_home: no
shell: /sbin/nologin
- name: setup04:create auth file
copy:
src: /etc/ansible/conf/rsync.password
dest: /etc/
mode: 600
- name: setup05:create backup dir
file:
dest: /backup
state: directory
owner: rsync
group: rsync
- name: setup06:boot rsync server
shell: rsync --daemon creates=/var/run/rsyncd.pid
- hosts: 172.16.1.31
tasks:
- name: setup01:create auth file
copy:
src: /etc/ansible/conf/rsync_client.password
dest: /etc/rsync.password
mode: 600
ansible一键部署脚本(NFS)
[root@m01 scripts]# cat nfs.yaml
# command playbook
#部署服务器
- hosts: nfs
tasks:
- name: setup01:install rpcbind server
yum:
name: nfs-utils
state: installed
- name: setup02:install rpcbind server
yum:
name: rpcbind
state: installed
- name: setup03:edit conf
copy:
src: /etc/ansible/conf/nfs_conf/exports
dest: /etc/
- name: setup04:create backup directory
file:
dest: /data
state: directory
owner: nfsnobody
group: nfsnobody
- name: setup05:boot rpc server
shell: /etc/init.d/rpcbind start
- name: setup06:boot nfs server
shell: /etc/init.d/nfs start
#部署客户端
- hosts: web
tasks:
- name: setup01:install nfs rpc
yum:
name: nfs-utils
state: installed
- name: setup02:install rpcbind server
yum:
name: rpcbind
state: installed
- name: setup03:mount
mount:
name: /mnt
src: 172.16.1.31:/data
fstype: nfs
state: mounted
一键部署inotify服务(在已有rsync服务的前提下)
#inotify.yaml文件
[root@m01 scripts]# cat inotify.yaml
# command playbook
- hosts: nfs
tasks:
- name: setup01:install inotify-tools
yum:
name: inotify-tools
state: installed
- name: setup02:inotify建立rsync服务的连接
shell: /bin/sh /server/scripts/inotify.sh &
# inotify脚本
[root@m01 scripts]# cat inotify.sh
#!/bin/bash
inotifywait -mrq --format "%w%f" -e create,delete,moved_to,close_write /data |\
while read line
do
rsync -az --delete /data/ rsync@172.16.1.41::backup --password-file=/etc/rsync.password
done
[root@m01 scripts]#
一键部署sersync服务(在已有rsync服务前提下)
[root@m01 sersync_conf]# cat /server/scripts/sersync.yaml
# command playbook
- hosts: nfs
tasks:
- name: setup01 dir tools
file:
dest: /tools
state: directory
- name: setup02:unzip sersync-master
unarchive:
src: /tools/sersync-master.zip
dest: /tools/
copy: yes
- name: setup03:tar sersync
unarchive:
src: /tools/sersync-master/sersync2.5.4_64bit_binary_stable_final.tar.gz
dest: /tools/
copy: no
- name: setup04:mv GNU-Linux-x86 to nfs
shell: mv /tools/GNU-Linux-x86 /usr/local/sersync
- name: setup05:edit conf
copy:
src: /etc/ansible/conf/sersync_conf/confxml.xml
dest: /usr/local/sersync/
- name: setup06:boot sersync
shell: /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml
一键部署Nginx服务
[root@m01 scripts]# cat nginx.yaml
# command playbook
- hosts: web
tasks:
- name: setup01:install pcre-devel
yum:
name: pcre-devel
state: installed
- name: setup02:install openssl-devel
yum:
name: openssl-devel
state: installed
- name: setup03:create www user
user:
name: www
state: present
create_home: no
shell: /sbin/nologin
- name: setup04:create dir
file:
dest: /server/tools
state: directory
- name: setup05:wget nginx
get_url:
url: http://nginx.org/download/nginx-1.15.8.tar.gz
dest: /server/tools
- name: setup06:tar nginx
unarchive:
src: /server/tools/nginx-1.15.8.tar.gz
dest: /server/tools
copy: no
- name: setup06:install nginx
shell: cd /server/tools/nginx-1.15.8;./configure --prefix=/application/nginx-15.
8 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module - name: setup07:make
shell: cd /server/tools/nginx-1.15.8;make && make install
- name: setup08:ln nginx
file:
src: /application/nginx-15.8
dest: /application/nginx
state: link
- name: setup09:boot nginx
shell: /application/nginx/sbin/nginx