1、

    #vim /etc/ansible/yaml/back.yml
- hosts: siyi
tasks:
- name: "yum rsync"
yum: name=rsync state=installed
- name: "配置rsync模块"
copy: backup=yes src=/etc/rsyncd.conf dest=/etc/rsyncd.conf
- name: "创建rsync用户"
user: name=rsync
- name: "创建backup目录"
file: name=/backup state=directory owner=rsync group=rsync
- name: "创建/server/tools/目录"
file: name=/server/tools/ state=directory owner=root group=root
- name: "开启rsync服务"
service: name=rsyncd state=started enabled=yes
- name: "创建密码文件"
file: name=/etc/rsync.password state=touch mode=600
- name: "添加密码"
blockinfile: path=/etc/rsync.password block='rsync_backup:oldboy'
- hosts: sanyi
tasks:
- name: "yum rsync"
yum: name=rsync state=installed
- name: "创建data目录"
file: name=/data state=directory
- name: "创建密码文件"
file: name=/etc/rsync.password state=touch mode=600
- name: "添加密码"
blockinfile: path=/etc/rsync.password block='oldboy'
- name: "添加bashrc"
blockinfile: path=/etc/bashrc block='export RSYNC_PASSWORD=oldboy'
- name: "执行bashrc"
shell: source /etc/bashrc
- name: "推送测试"
command: rsync -az /tmp rsync_backup@172.16.1.41::backup/
- name: "解压监控包"
command: tar -xf /server/tools/application.tar.gz -C /server/tools/
- name: "创建日志目录"
file: name=/application/logs/ state=directory
- name: "创建日志文件"
file: name=/application/logs/rsync_fail_log.sh state=touch
- name: "执行监控"
command: /server/tools/application/bin/sersync2 -d -o /server/tools/application/conf/confxml.xml
- name: "yum nfs"
yum: name=nfs-utils state=installed
- name: "yum rpcbind"
yum: name=rpcbind state=installed
- name: "开启rpcbind服务"
service: name=rpcbind state=started enabled=yes
- name: "开启nfs服务"
service: name=nfs state=started enabled=yes
- name: "添加共享目录"
blockinfile: path=/etc/exports block='/data 172.16.1.0/24(rw,sync)'
- name: "重启nfs服务"
service: name=nfs state=restarted
- name: "修改data属主"
file: name=/data owner=nfsnobody group=nfsnobody
- hosts: oldboy
tasks:
- name: "yum nfs-utils rpcbind"
yum: name=nfs-utils state=installed
- name: "yum nfs-utils rpcbind"
yum: name=rpcbind state=installed
- name: "开启rpcbind服务"
service: name=rpcbind state=started enabled=yes
- name: "挂载"
mount: src='172.16.1.31:/data' state=mounted fstype=nfs name=/mnt
- name: "添加执行权限"
file: name=/etc/rc.local mode=755
- name: "添加密码"
blockinfile: path=/etc/rc.local block='/usr/bin/mount -t nfs 172.16.1.31:/data /mnt'

4、m01的/server/scripts/目录下

        # vim /server/scripts/mokuai.sh
#!/bin/bash
cd /root/.ssh/ &&\
rm -f * &&\
/bin/ssh-keygen -t rsa -f /root/.ssh/id_rsa -P "" &>/dev/null
yum install -y sshpass >/dev/null 2>&1
for n in 7 8 31 41
do
sshpass -p123456 ssh-copy-id -i ~/.ssh/id_rsa.pub 172.16.1.$n -o StrictHostKeyChecking=no &>/dev/null
if [ $? -eq 0 ]
then
echo "172.16.1.$n Distribute successfully "
else
echo "172.16.1.$n Distribute no successfully "
fi
done &&\
scp -P 22 -rp /server/tools/application.tar.gz root@172.16.1.31:/server/tools/ &>/dev/null &&\
cp /etc/ansible/hosts{,.ori} &&\
cat >/etc/ansible/hosts<<EOF
[siyi]
172.16.1.41 [sanyi]
172.16.1.31 [oldboy]
172.16.1.7
172.16.1.8
EOF
cp /etc/rsyncd.conf{,.ori} &&\
cat >/etc/rsyncd.conf<<EOF
#rsync_config_______________start
#created by oldboy
#site: http://www.oldboyedu.com
uid = rsync
gid = rsync
use chroot = no
fake super = yes
max connections = 200
timeout = 600
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = welcome to oldboyedu backup!
path = /backup/
EOF
sed -i '71s/#//' /etc/ansible/ansible.cfg &&\
ansible-playbook /etc/ansible/yaml/back.yml

ansible 模块的更多相关文章

  1. ansible模块

    ansible模块: 模块(Modules),类似于 "任务插件"("task plugins")或"库插件"("library ...

  2. ansible笔记(3):ansible模块的基本使用

    ansible笔记():ansible模块的基本使用 在前文的基础上,我们已经知道,当我们使用ansible完成实际任务时,需要依靠ansible的各个模块,比如,我们想要去ping某主机,则需要使用 ...

  3. 第4天:Ansible模块

    Ansible对远程服务器的实际操作实际是通过模块完成的,其工作原理如下: 1)将模块拷贝到远程服务器 2)执行模块定义的操做,完成对服务器的修改 3)在远程服务器中删除模块 需要说明的是,Ansib ...

  4. ansible模块command、shell、raw、script

    简介 环境: ansible端: ip:192.168.100.129 hostname:node1.lansgg.com client端: ip:192.168.100.131 hostname:v ...

  5. win10的pycharm中安装ansible模块过程

    前面的安装报错信息 ansible模块安装报错:Could not install packages due to an OSError: [Errno 2] No such file or dire ...

  6. Ansible 模块命令介绍

    copy模块: 目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上 命令:ansible 10.1.1.113 -m copy -a 'src=/root/a.sh dest=/tmp/' ...

  7. ansible 模块 分享

    A a10_server 管理A10 Networks AX / SoftAX / Thunder / vThunder设备 a10_service_group 管理A10网络设备的服务组 a10_v ...

  8. ansible模块学习

    ansible的功能: 模块化任务,调用特定的模块,完成特定的任务 基于python语言实现,由paramiko.pyyaml和jinja2三个模块构建 部署简单,agentless,ansible基 ...

  9. 4.1、Ansible模块

    ansible-doc -l    列出所有模块 ansible-doc 模块名    查看模块的help说明 ansible-doc -s  module_name:获取指定模块的使用信息 ***文 ...

随机推荐

  1. jquery mobile 建wap站

    使用jquery mobile 建手机wap站: 几篇比较好的文章 http://wap.yesky.com/dev/225/30974725.shtml http://tech.it168.com/ ...

  2. Python基础(random模块)

    random 常用的方法: #Author : Kelvin #Date : 2019/1/6 15:33 import random print(random.random()) #产生0-1之间的 ...

  3. Python爬虫入门教程 50-100 Python3爬虫爬取VIP视频-Python爬虫6操作

    爬虫背景 原计划继续写一下关于手机APP的爬虫,结果发现夜神模拟器总是卡死,比较懒,不想找原因了,哈哈,所以接着写后面的博客了,从50篇开始要写几篇python爬虫的骚操作,也就是用Python3通过 ...

  4. C#线程安全使用(五)

     CancellationToken的多种应用 这是线程安全的最后一篇了,主要介绍CancellationToken的多种应用. 1,ThreadPool直接启动线程,传递CancellationTo ...

  5. SpringBoot基础系列-SpringCache使用

    原创文章,转载请标注出处:<SpringBoot基础系列-SpringCache使用> 一.概述 SpringCache本身是一个缓存体系的抽象实现,并没有具体的缓存能力,要使用Sprin ...

  6. javascript中的typeof和类型判断

    typeof ECMAScript 有 5 种原始类型(primitive type),即 Undefined.Null.Boolean.Number 和 String.我们都知道可以使用typeof ...

  7. 0423上课练习(list、while、def)

    """ 循环录入3个正整数,求最大值,最小值,总和,平均值 访问列表中的元素: 列表的长度: len(列表名) 索引值的范围:[0,len(列表名)-1] 列表名[索引值 ...

  8. Nginx + Keepalived实现应用高可用负载均衡功能

    说明:此处仅介绍 Keepalived 实现nginx负载均衡器的高可用,关于nginx介绍和负载均衡实现可查看我的另两篇博文 Nginx负载均衡 和 Nginx配置了解 应用背景:实现高可用,避免单 ...

  9. 正确启动从GitHub上下载的vue项目:vueAdmin-template

    先讲重点,后上相关资料: 遇到的问题:在启动从GitHub上下载的vue项目:vueAdmin-template 时报错:'webpack-dev-server' 不是内部或外部命令,也不是可运行的程 ...

  10. weblogic patch log显示

    如何在WebLogic 12.1.3 版本的 server log 中显示 opatch 的补丁信息? 打补丁  patch 23558563 之后. 需要在 JAVA_OPTIONS 中添加如下参数 ...