码迷,mamicode.com
首页 > 其他好文 > 详细

ansbile简单应用

时间:2017-03-12 11:32:44      阅读:529      评论:0      收藏:0      [点我收藏+]

标签:config   crypto   exec   ima   使用   简介   ever   ice   sshd   

一、简介

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 <host-pattern> [-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模块使用,创建目录,并赋予权限

技术分享

用file模块,做软连接

技术分享

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

ansible all -m yum -a "name=tree state=installed"

name:指定安装包名

state:指定方式,安装或卸载

安装: install (`present‘ or `installed‘, `latest‘),

卸载:remove (`absent‘ or `removed‘) a package

ansible all -m yum -a "name=httpd* state=latest"       #安装httpd服务

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

技术分享

 

ansbile简单应用

标签:config   crypto   exec   ima   使用   简介   ever   ice   sshd   

原文地址:http://www.cnblogs.com/yangxu01/p/6537062.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!