ansible 模块
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 模块的更多相关文章
- ansible模块
ansible模块: 模块(Modules),类似于 "任务插件"("task plugins")或"库插件"("library ...
- ansible笔记(3):ansible模块的基本使用
ansible笔记():ansible模块的基本使用 在前文的基础上,我们已经知道,当我们使用ansible完成实际任务时,需要依靠ansible的各个模块,比如,我们想要去ping某主机,则需要使用 ...
- 第4天:Ansible模块
Ansible对远程服务器的实际操作实际是通过模块完成的,其工作原理如下: 1)将模块拷贝到远程服务器 2)执行模块定义的操做,完成对服务器的修改 3)在远程服务器中删除模块 需要说明的是,Ansib ...
- ansible模块command、shell、raw、script
简介 环境: ansible端: ip:192.168.100.129 hostname:node1.lansgg.com client端: ip:192.168.100.131 hostname:v ...
- win10的pycharm中安装ansible模块过程
前面的安装报错信息 ansible模块安装报错:Could not install packages due to an OSError: [Errno 2] No such file or dire ...
- Ansible 模块命令介绍
copy模块: 目的:把主控端/root目录下的a.sh文件拷贝到到指定节点上 命令:ansible 10.1.1.113 -m copy -a 'src=/root/a.sh dest=/tmp/' ...
- ansible 模块 分享
A a10_server 管理A10 Networks AX / SoftAX / Thunder / vThunder设备 a10_service_group 管理A10网络设备的服务组 a10_v ...
- ansible模块学习
ansible的功能: 模块化任务,调用特定的模块,完成特定的任务 基于python语言实现,由paramiko.pyyaml和jinja2三个模块构建 部署简单,agentless,ansible基 ...
- 4.1、Ansible模块
ansible-doc -l 列出所有模块 ansible-doc 模块名 查看模块的help说明 ansible-doc -s module_name:获取指定模块的使用信息 ***文 ...
随机推荐
- MySQL自定义函数与存储过程
1.前置条件 MySQL数据库中存在表user_info,其结构和数据如下: mysql> desc user_info; +-----------+----------+------+---- ...
- 【转载】java static 关键字的四种用法
原文链接点这里,感谢博主分享 在java的关键字中,static和final是两个我们必须掌握的关键字.不同于其他关键字,他们都有多种用法,而且在一定环境下使用,可以提高程序的运行性能,优化程序的结构 ...
- 💈 线程间互访助手类 (EN)
Conmajia © 2012, 2018 Published on August 5th, 2012 Updated on February 2nd, 2019 Introduction While ...
- Android SDK 开发——发布使用踩坑之路
前言 在 Android 开发过程中,有些功能是通用的,或者是多个业务方都需要使用的. 为了统一功能逻辑及避免重复开发,因此将该功能开发成一个 SDK 是相当有必要的. 背景 刚好最近自己遇到了类似需 ...
- HashMap源码分析 JDK1.8
本文按以下顺序叙述: HashMap的感性认识. 官方文档中对HashMap介绍的解读. 到源码中看看HashMap这些特性到底是如何实现的. 把源码啃下来有一种很爽的感觉, 相信你读完后也能体会到~ ...
- Nginx + Keepalived实现应用高可用负载均衡功能
说明:此处仅介绍 Keepalived 实现nginx负载均衡器的高可用,关于nginx介绍和负载均衡实现可查看我的另两篇博文 Nginx负载均衡 和 Nginx配置了解 应用背景:实现高可用,避免单 ...
- java的设计模式 - 静态工厂方法
静态工厂方法,也不知道为何叫这个名字.其实也就是一个静态函数,可以替代构造函数用.大名鼎鼎的 guava 就大量使用这种模式,这是非常有用的模式. 比如是 Integer i = Integer.va ...
- composer windows下安装
composer windows安装 因要使用PhpSpreadsheet处理excel表格 选择composer安装 1. 下载Composer-Setup.exe 2.点击直接运行---选择ph ...
- webstorm 2018.2.3 cmd+w无法关闭文件
- 禁用事件event默认行为
在大多数情况下,为事件处理函数返回false,可以防止默认的事件行为.例如,默认情况下点击一个<a>元素,页面会跳转到该元素href属性指定的页. js中return false作用一般是 ...