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

ansible

时间:2016-04-06 18:54:44      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:ansible


ansible 主要参数


-u  指定ssh 连接用户名 

-i   指定/etc/snsible/hosts 文件位置

-m  指定使用的模块  如 shell  yum copy script 

-f 10  指定并发数 

-k   用来输入密码

-a 指定模块的参数 可以是命令等等



ansible 安装



centos 直接是yum安装即可  安装之前 先安装epel源码

rpm -Uvh  http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm


yum install ansible -y 安装即可



定义组 


vim /etc/ansible/hosts 


# This is the default ansible ‘hosts‘ file.

#

# It should live in /etc/ansible/hosts

#

#   - Comments begin with the ‘#‘ character

#   - Blank lines are ignored

#   - Groups of hosts are delimited by [header] elements

#   - You can enter hostnames or ip addresses

#   - A hostname/ip can be a member of multiple groups


# Ex 1: Ungrouped hosts, specify before any group headers.



# Ex 2: A collection of hosts belonging to the ‘webservers‘ group


[webservers]   组1 


192.168.80.63



# If you have multiple hosts following a pattern you can specify

# them like this:



# Ex 3: A collection of database servers in the ‘dbservers‘ group


[dbservers]    组2 


192.168.80.64   


# Here‘s another example of host ranges, this time there are no

# leading 0s:


远程执行命令


ansible -k -i /etc/ansible/hosts all -a "ls"   免秘钥不用-k

ansible -k -m shell -i /etc/ansible/hosts all -a ‘ifconfig |grep Bcast‘ 


ansible 正则表达式使用 


ansible all -k -a ‘df -h‘

ansible -k -m shell all -a "ifconfig |grep Bcast" 


批量拷贝文件


ansible all -k -m copy -a ‘src=/root/hanwei dest=/root/ mode=755 owner=root‘



本文出自 “秋水无痕” 博客,谢绝转载!

ansible

标签:ansible

原文地址:http://7456193.blog.51cto.com/7446193/1760982

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