ansbile简单应用

ansbile简单应用
一、简介

Ansible is a radically simple configuration-management, application deployment, task-execution, and multinode orchestration engine.
Design Principles
Have a dead simple setup process and a minimal learning curve
Be super fast & parallel by default
Require no server or client daemons; use existing SSHd
Use a language that is both machine and human friendly
Focus on security and easy auditability/review/rewriting of content
Manage remote machines instantly, without bootstrapping
Allow module development in any dynamic language, not just Python
Be usable as non-root
Be the easiest IT automation system to use, ever.

二、安装
ansible依赖于Python 2.6或更高的版本、paramiko、PyYAML及Jinja2。
2.1 编译安装
解决依赖关系

# yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto
# tar xf ansible-1.5.4.tar.gz
# cd ansible-1.5.4
# python setup.py build
# python setup.py install
# mkdir /etc/ansible
# cp -r examples/* /etc/ansible
2.2 rpm包安装
# yum install ansible

注意:不同版本的ansible的功能差异可能较大。

三、简单应用
ansible通过ssh实现配置管理、应用部署、任务执行等功能,因此,需要事先配置ansible端能基于密钥认证的方式联系各被管理节点。

ansible [-f forks] [-m module_name] [-a args]
-m module:默认为command

ansible-doc: Show Ansible module documentation
-l, –list List available modules
-s, –snippet Show playbook snippet for specified module(s)
实例应用:

ssh-keygen -t rsa -P ''    
ssh-copy-id -i .ssh/id_rsa.pub root@103.242.135.25   

一、定义host
这里写图片描述

注:一个主机可以定义于多个不同组 解决通信问题:1.直接可以编辑文件加入密码 2.可以基于ssh秘钥认证方式进行

ping模块使用,也可以使用单个主机或者已定义好的组名,这里使用all,代表所有主机

这里写图片描述

command模块使用,创建目录!可以使用linux系统命令

这里写图片描述

shell模块使用,命令中执行管道,重定向之类的需使用shell模块

这里写图片描述

shell模块和command模块的区别

这里写图片描述

cpoy模块使用,cp本地的1.html到远端主机的/root目录下,必须使用绝对路径

这里写图片描述

cron模块,批量执行定时任务

这里写图片描述
state=absent 删除指定name对应的任务计划

fetch拉取模块,将远端的文件拉到本地,和copy模块相反

这里写图片描述
file模块使用,创建目录,并赋予权限

使用yum模块,批量安转tree工具包

ansible all -m yum -a “name=tree state=installed”
name:指定安装包名
state:指定方式,安装或卸载
安装: install (present' orinstalled’, latest'),
卸载:remove (
absent’ or `removed’) a package
ansible all -m yum -a “name=httpd* state=latest” #安装httpd服务

service模块使用,关闭服务:stopped 开启服务:started

这里写图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值