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. Navicat 导出sql问题

    楼主最近碰到一个问题: 使用Navicat建立数据模型的时候使用导出sql功能导出的sql脚本放在sqlserver中执行失败,表创建成功了,但是我在Navicat中写的表注释和字段注释都没有成功, ...

  2. Java基础之 反射是什么?

    什么是反射,反射能干嘛? 反射是:指程序可以访问.检测和修改它本身状态或行为的一种能力 反射是一种能力,所以给的定义就是说明了它能干嘛. 我们平时用反射主要做: 获取类型的相关信息 动态调用方法 动态 ...

  3. 第四章:shiro的INI配置

    4.1 根对象SecurityManager 从之前的Shiro架构图可以看出,Shiro是从根对象SecurityManager进行身份验证和授权的:也就是所有操作都是自它开始的,这个对象是线程安全 ...

  4. Spring RestTemplate详解

    Spring RestTemplate详解   1.什么是REST? REST(RepresentationalState Transfer)是Roy Fielding 提出的一个描述互联系统架构风格 ...

  5. jsp内置对象-session对象

    一.session概述 隐含对象session是javax.servlet.http.HttpSession接口实现类的对象,用于保存用户的状态信息. 在web开发中,服务器为每个用户浏览器创建一个会 ...

  6. Dynamics 365 启用跟踪及读取跟踪文件工具

    微软动态CRM专家罗勇 ,回复315或者20190313可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!我的网站是 www.luoyong.me . 当根据错误提示排查问 ...

  7. 使用AndroidStudio编写APICloud模块需要注意的地方,解决模块未定义。

    在新的版本下,使用AndroidStudio编写APICloud模块,已经非常简单了,解决模块未定义,最重要的就是要先看官方的视频! 注意在模块的module.json中name很重要,建议做到三统一 ...

  8. MongoDB 集合间关联查询后通过$filter进行筛选

    在前面的分享中,有讲解 “详解MongoDB中的多表关联查询($lookup)” 一节,其内容涵盖了常见的集合管理的需求.我们知道文档的选择都是通过$match进行匹配刷选.但这是文档间的匹配筛选,并 ...

  9. NTFS权限和共享权限的区别

    共享权限 共享权限有三种:完全控制.更改.读取 共持本地安全性.换句话说,他在同一台计算机上以不同用户名登录,对硬盘上同一文件夹可以有不同的访问权限. 注意:NTFS权限对从网络访问和本机登录的用户都 ...

  10. Win32 Ime

    Win32 Ime API: ImmGetContext: 获取指定窗口的当前的输入上下文,然后再尝试访问上下文中的信息.应用程序应该定期使用这个功能获取窗口的当前的输入上下文.若hWnd参数为零,将 ...