自动化工具-ansible服务部署与使用
1.前言
1.1ansible软件介绍
1.2ansible软件特点:
1.3ansible服务端和被控端环境:
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) ansible被控端: 192.168.10.144: [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 192.168.10.143: [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
2.实现基于秘钥连接:
3.安装ansible和配置主机组
3.1安装:
3.2配置ansible主机组
[web] #主机组 192.168.10.144 ansible_ssh_user=root ansible_ssh_pass=123 #主机的用户名和密码,如果不是公钥验证,也可以尝试密码连接 192.168.10.145 [mysql] 47.94.20.198
4.ansible软件使用/参数
5.ansible常用模块
5.1 command模块
[root@localhost ansible]# ansible web -a 'chdir=/home ls' 192.168.10.145 | SUCCESS | rc=0 >> 192.168.10.144 | SUCCESS | rc=0 >> abc1 abc2 abc3
5.2File模块
- directory:如果目录不存在,创建目录
- file:即使文件不存在,也不会被创建
- link:创建软链接;hard:创建硬链接
- touch:如果文件不存在,则会创建一个新的文件,如果已存在,则更新其最后修改时间
- absent:删除目录/文件或者取消链接文件
[root@localhost ~]# ansible web -m file -a 'path=/tmp/test.txt state=touch'
192.168.10.145 | SUCCESS => {
"changed": true,
"dest": "/tmp/test.txt",
"gid": 0,
"group": "root",
"mode": "0644",
"owner": "root",
"size": 0,
"state": "file",
"uid": 0
}
192.168.10.144 | SUCCESS => {
"changed": true,
"dest": "/tmp/test.txt",
"gid": 0,
"group": "root",
"mode": "0644",
"owner": "root",
"secontext": "unconfined_u:object_r:user_tmp_t:s0",
"size": 0,
"state": "file",
"uid": 0
[root@localhost ~]# ansible web -m file -a 'path=/tmp/test_dir state=directory owner=root group=root mode=777'
192.168.10.145 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"path": "/tmp/test_dir",
"size": 6,
"state": "directory",
"uid": 0
}
192.168.10.144 | SUCCESS => {
"changed": true,
"gid": 0,
"group": "root",
"mode": "0777",
"owner": "root",
"path": "/tmp/test_dir",
"secontext": "unconfined_u:object_r:user_tmp_t:s0",
"size": 6,
"state": "directory",
"uid": 0
}
root@localhost ~]# ansible web -m service -a "name=postfix state=started enabled=yes"
5.4 cron模块 用于管理计划任务
ansible web -s cron -a "minute=0 hour=3 job='/bin/sh /mnt/shell/hostname.sh' name=check hostname"
5.5 yum模块 使用yum包管理器来管理软件包
ansible web -m yum -a 'name=libselinux-python state=installed'
yum卸载软件:
[root@localhost ~]# ansible web -m yum -a 'name=lrzsz state=removed'
192.168.10.145 | SUCCESS => {
"changed": false,
"msg": "",
"rc": 0,
"results": [
"lrzsz is not installed"
]
}
192.168.10.144 | SUCCESS => {
"changed": true,
"msg": "",
"rc": 0,
"results": [
"已加载插件:fastestmirror, langpacks\n正在解决依赖关系\n--> 正在检查事务\n---> 软件包 lrzsz.x86_64.0.0.12.20-36.el7 将被 删除\n--> 解决依赖关系完成\n\n依赖关系解决\n\n================================================================================\n Package 架构 版本 源 大小\n================================================================================\n正在删除:\n lrzsz x86_64 0.12.20-36.el7 @base 181 k\n\n事务概要\n================================================================================\n移除 1 软件包\n\n安装大小:181 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n 正在删除 : lrzsz-0.12.20-36.el7.x86_64 1/1 \n 验证中 : lrzsz-0.12.20-36.el7.x86_64 1/1 \n\n删除:\n lrzsz.x86_64 0:0.12.20-36.el7 \n\n完毕!\n"
]
}
5.6 script模块
在远程主机上执行脚本
[root@www ansible]# ansible mailserver -m script -a '/bin/bash /tmp/po2.sh'
自动化工具-ansible服务部署与使用的更多相关文章
- 自动化运维工具Ansible详细部署 (转载)
自动化运维工具Ansible详细部署 标签:ansible 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://sofar.blog. ...
- 自动化运维工具Ansible详细部署 - 人生理想在于坚持不懈 - 51CTO技术博客
自动化运维工具Ansible详细部署 - 人生理想在于坚持不懈 - 51CTO技术博客 自动化运维工具Ansible详细部署
- ansible服务部署与使用
第1章 ssh+key实现基于密钥连接(ansible使用前提) 说明: ansible其功能实现基于SSH远程连接服务 使用ansible需要首先实现ssh密钥连接 1.1 部署ssh ...
- 运维自动化工具ansible
企业级自动化运维工具应用实战ansible 公司计划在年底做一次大型市场促销活动,全面冲刺下交易额,为明年的上市做准备.公司要求各业务组对年底大促做准备,运维部要求所有业务容量进行三倍的扩容,并搭建出 ...
- 在 CentOS 7 中安装并使用自动化工具 Ansible
Ansible是一款为类Unix系统开发的自由开源的配置和自动化工具.它用Python写成,类似于Chef和Puppet,但是有一个不同和优点是我们不需要在节点中安装任何客户端.它使用SSH来和节点进 ...
- 自动化运维工具Ansible详细部署
本文来源:http://sofar.blog.51cto.com/353572/1579894/ 前言 一个由 Python 编写的强大的配置管理解决方案.尽管市面上已经有很多可供选择的配置管理解决方 ...
- 自动化运维工具Ansible的部署步骤详解
本文来源于http://sofar.blog.51cto.com/353572/1579894,主要是看到这样一篇好文章,想留下来供各位同僚一起分享. 一.基础介绍 ================= ...
- 在Debian 8 上安装自动化工具Ansible
如果你是新手,就不要犹豫了,ansible是你最好的选择,本人菜鸟一个.废话少说,开始安装! 实验环境: 192.168.3.190 192.168.3.191 192.168.3.192 192.1 ...
- 运维工具Ansible安装部署
http://blog.51cto.com/liqingbiao/1875921 centos7安装部署ansible https://www.cnblogs.com/bky185392793/p/7 ...
随机推荐
- .NET Core开发日志——GraphQL
GraphQL是什么 GraphQL既是一种用于API的查询语言也是一种通过使用对应数据的类型系统,执行数据查询的服务端运行时.GraphQL没有局限于任何数据库或存储引擎,而是通过既有代码及数据获得 ...
- iOS UIView 选择性倒角
有些APP中会有卡券,卡券做成了选择性倒角,例如左上,右上倒角.非常美观.看一下iOS的实现: #import "Masonry.h" @interface WJWDaojiaoV ...
- js基础--数据类型
1,数据类型 Number:包括小数与整数,负数,NaN ,Infinity无限大String字符串:‘abc’Boolean布尔值:true or falsenull 空undefined 未定义 ...
- GMT\UTC YYYY-MM-DDTHH:mm:ss.sssZ、YYYY-MM-DDTHH:mm:ss.sss+8:00意义及与北京时间转换
UTC: Universal Time Coordinated 协调世界时,又称世界标准时间. GMT: Greenwich Mean Time 格林尼治平均时. 格林尼治标准时间的正午是指当太阳横穿 ...
- 小白用阿里云搭载wordpress个人博客
阿里云服务已经购买多时,却一直没时间部署内容,借着这次机会自己照着博客园园友的方式用wordpress搭建了个人博客! 创建wordpress的内容就不多说了,直接附链接来源:https://www. ...
- 关于SQL配置管理工具无法打开0x8004100e问题!
今天犯了个很“2”得问题,因为在远程数据库可以访问,并且也在安装程序中有看到装有SQLserver Mamngement Studio及其它程序,所以想在本地使用数据库应该可以但没想却总是报SQL配置 ...
- JVM深入:JVM内存堆布局图解分析(转)
转载自:https://www.cnblogs.com/SaraMoring/p/5713732.html 原文:http://www.codeceo.com/article/jvm-memory-s ...
- 69.js--点击事件等比例弹出层div
html:<!--弹出层导航栏--> <div class="public-nav-content"> <ul> <li><a ...
- Leetcode: Sliding Window Median
Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...
- java快排思想
1分治思想 1.1比大小在分区 1.2从数组中取出一个数做基准数 1.3将比他小的数全放在他的左边,比他大的数全放在他的右边 1.4然后递归 左边 和右边 }