ansible

简介:

ansbile:

运维工作:系统安装(物理机,虚拟机)--》程序包安装,配置,服务启动 --》批量操作 --》程序发布 --》监控

OS provisioning;

物理机:PXE、cobbler

虚拟机:image templates

configration:

puppet(ruby)

saltstack(python)

chef

cfengine

Command and control:

fabric

预发布验证:

新版本的代码先发布到服务器(跟线上环境配置完全相同,只是未接入调度器)

程序发布:

不能影响用户体验;

系统不能停机;

不能导致系统故障或造成系统完全不可用;

灰度发布;

发布路径:

/webapp/tuangou-1.1

/web/app/tuangou

/webapp/tuangou-1.2

在调度器上关闭一批主机(maintanace)--> 关闭服务 --> 部署新版本的应用程序 -->启动服务 --> 调度器上启用这一批服务器

自动化灰度发布:脚本、发布平台;

运维工具的分类;

agent:puppet,func

agentless:ansible,fabric

ssh

ansible:

模块化,调用特定的模块,完成特定的任务;

基于python语言实现,由paramiko、PyYAML和Jinja2三个关键模块;

部署简单,agentless;

主从模式

支持自定义模块

支持playbook

幂等性;

配置文件;

/etc/ansible/ansbile.cfg

/etc/ansible/hosts

for i in 15 16 17; do ssh 172.16.6.$i 'date';done

查看某个命令的具体用法:

ansible-doc -s command

ansible 172.16.6.15 -m command -a 'ifconfig'

ansible all -m command -a 'ifconfig'

ansible all -a 'ping'

下载FTP文件;

ansible webservers -a 'wget -O /tmp/apr-1.4.6.tar.bz2  ftp://172.16.6.49:2121/mage-app/sources/httpd/apr-1.4.6.tar.bz2'

创建用户:

ansible webservers -m user -a 'name=hacluster state=present'

删除用户;

ansible webservers -m user -a 'name=hacluster state=absent'

常用模块:

command:直接运行命令

-a ‘COMMAND’

user:添加用户

-a ‘name= state=  system= ’

group:添加组

-a 'name= gid= state= system= '

cron:添加计划任务

-a 'name= minute= hour= day= month weekday= job= user= state= '

ansible all -m cron -a 'name="sync time from ntpserver" minute="*/10" job="/sbin/ntpdate 172.16.6.14 & > /dev/null"'

ansible all -m cron -a 'name="sync time from ntpserver" state=absent’

copy:文件复制

-a 'dest= src= mode= owner= group'

ansible all -m copy -a 'src=/etc/fstab dest=/tmp/fstab.tmp mode=600'

file:创建删除文件夹,创建链接

-a 'path= mode= owner= group= state=(link\directory\present\absent)'

创建文件,链接,删除链接

ansible all -m file -a 'path=/tmp/testdir state=directory'

ansible all -m file -a 'path=/tmp/testdir state=link src=/tmp/fstab.tmp force=yes'

ansible all -m file -a 'path=/tmp/testdir state=absent src=/tmp/fstab.tmp force=yes'

ping

ansible all -m ping

yum:yum安装包

-a 'name= state=present\latest\absent'

ansible webservers -m yum -a 'name=ftp state=latest'

service:服务启动停止 

-a 'name= state=started\stopped\restarted enabled=yes'

ansible webservers -m service -a 'name=httpd state=started enabled=yes'

shell:远程运行shell命令

-a 'command'

ansible webservers -m shell -a 'echo centos | passwd --stdin centos'

script:远程运行本地shell脚本

-a '/path/test.sh'

ansible webservers -m script -a '/tmp/cc.sh'

setup:获取信息

ansible webservers -m setup





     本文转自阿伦艾弗森 51CTO博客,原文链接:http://blog.51cto.com/perper/1978158,如需转载请自行联系原作者



相关文章
|
5月前
|
关系型数据库 MySQL PHP
ansible汇总(3)
roles介绍 roles(角色): 就是通过分别将variables, tasks及handlers等放置于单独的目录中,并可以便捷地调用它们的一种机制。
34 1
|
5月前
|
Kubernetes Docker 容器
ansible汇总(2)
playbook(剧本): 是ansible用于配置,部署,和管理被控节点的剧本。用于ansible操作的编排。 参考:https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html 使用的格式为yaml格式(saltstack,elk,docker,docker-compose,kubernetes等也都会用到yaml格式)
31 0
|
8月前
|
运维 网络安全 Python
ansible-1
ansible-1
28 0
|
9月前
|
网络安全 开发工具
ansible-2
ansible-2
42 1
|
9月前
|
XML 关系型数据库 应用服务中间件
|
9月前
|
运维 Shell 网络安全
ansible(1)
Ansible概述:是一个配置管理系统(configuration management system),当下最流行的批量自动化运维工具之一.
|
10月前
|
存储 安全 Linux
ansible 初识
Ansible是一个开源配置管理工具,可以使用它来自动化任务,部署应用程序实现IT基础架构。Ansible可以用来自动化日常任务,比如,服务器的初始化配置、安全基线配置、更新和打补丁系统,安装软件包等。
81 1
|
运维 网络安全 开发工具
ansible使用
ansible使用
186 0
|
测试技术 Go Apache
|
监控 Shell 网络安全
Ansible 常用
一.前言 在企业中运维工作人员通常需要同时管理几十台甚至几百台主机(虚拟机),如果需要批量修改设置或者做更新操作的话,即便是事先编写好脚本,一台一台的去运行脚本也是非常耗时的,效率也十分低下。
1216 0