您的位置:首页 > 其它

Ansible

2016-04-12 11:04 246 查看
1. Benifts

不需要后台进程,不需要数据库。

被管节点不需要agent.

不要求root权限

2. Requirment

manage node: >=python2.6

managed node: >=python2.4

----------------------------------------------------------------------------

role: 

把配置文件整合到一起并最大程度保证其刚劲整洁,可重用

----------------------------------------------------------------------------

3. 简单命令

ansible -i hosts all -m ping -u user

-i:指定 inventory 文件,使用当前目录下的 hosts
all:针对 hosts 定义的所有主机执行,这里也可以指定组名或模式
m:指定所用的模块,我们使用 Ansible 内置的 ping 模块来检查能否正常管理远端机器
-u:指定远端机器的用户

ansible all -m shell -a "cat /root/.ssh/id_rsa.pub >> /root/.ssh/bbb"

ansible testservers -m command -a 'uname -a'

2. 剧本

剧本播放:

ansible-playbook deploy-blog-simple.yml

ansible-playbook -i hosts-demo site.yml

ansible-playbookpropel-vagrant-dev/provisioning/site.yml --extra-vars"@./propel-vagrant-dev/config.yml"

常用模块

1. command

在远程主机上执行命令

The command module
takes the command name followed by a listof space-delimited arguments. The given command will be executed on allselected nodes. It will not be processed through the shell, so variableslike 
$HOME andoperations
like 
"<"">""|",and "&" willnot
work (use the 
shellmodule
if you need these features).


 ansible testservers -m shell -a 'ls -al'

2. shell

切换到某个shell执行指定的指令,参数与command相同。

## 将创建的脚本文件分发到远程

# ansible storm_cluster -m copy -a "src=/tmp/rocketzhang_test.sh dest=/tmp/rocketzhang_test.sh owner=root group=root mode=0755"

## 远程执行

# ansible storm_cluster -m shell -a "/tmp/rocketzhang_test.sh"
3.setup
用来查看远程主机的一些基本信息

ansible
storm_cluster -m setup

4. ping

## 用来测试远程主机的运行状态

# ansible storm_cluster -m ping
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: