ansible记录

http://www.ansible.com.cn/docs/intro_getting_started.html
1,看文档说按装ansible,只需要源码就可以直接启动,并且在被管理节点上不需要安装别的软件,依赖ssh,sftp(可以配置成scp方式)
2,Ansible 1.3及之后的版本默认会在本地的 OpenSSH可用时会尝试用其进行远程通讯.这会启用ControlPersist(一个性能特性),Kerberos,和在~/.ssh/config中的配置选项如 Jump Host setup.然而,当你使用Linux企业版6作为主控机(红帽企业版及其衍生版如CentOS),其OpenSSH版本可能过于老旧无法支持ControlPersist. 在这些操作系统中,Ansible将会退回并采用 paramiko (由Python实现的高质量OpenSSH库). 如果你希望能够使用像是Kerberized SSH之类的特性,烦请考虑使用Fedora, OS X, 或 Ubuntu 作为你的主控机直到相关平台上有更新版本的OpenSSH可供使用,或者启用Ansible的“accelerated mode”
3在/etc/ansible/hosts中添加受管理机器,需要配置authorized_keys
4ping所有节点
ansible all -m ping
5Ansible将会对远程系统模块参数记录在远程的syslog中,除非一个任务或者play被标记了“no_log: True”属性
6主机分组的信息在/etc/ansible/hosts文件中配置,例如:
mail.example.com

[webservers]
foo.example.com
bar.example.com

[dbservers]
one.example.com
two.example.com
three.example.com

如果ssh端口号不是默认的22,可以指定具体端口
badwolf.example.com:5309

规则匹配分组
badwolf.example.com:5309
指定连接方式
[targets]

localhost ansible_connection=local
other1.example.com ansible_connection=ssh ansible_ssh_user=mpdehaan
other2.example.com ansible_connection=ssh ansible_ssh_user=mdehaan

主机变量
[atlanta]
host1 http_port=80 maxRequestsPerChild=808
host2 http_port=303 maxRequestsPerChild=909

对atlanta组下的机器执行reboot命令,每次开10个并行
ansible atlanta -a “/sbin/reboot” -f 10
指定用户执行
ansible atlanta -a “/usr/bin/foo” -u username
执行shell命令,需要注意必须是单引号
ansible raleigh -m shell -a ‘echo $TERM’
拷贝文件
ansible atlanta -m copy -a “src=/etc/hosts dest=/tmp/hosts”
修改属主和权限
ansible webservers -m file -a “dest=/srv/foo/b.txt mode=600 owner=mdehaan group=mdehaan”
创建目录
ansible webservers -m file -a “dest=/path/to/c mode=755 owner=mdehaan group=mdehaan state=directory”
递归删除目录
ansible webservers -m file -a "dest=/path/to/c state=absent
user模块管理用户
$ ansible all -m user -a “name=foo password=”

$ ansible all -m user -a “name=foo state=absent”

调用git模块,部署webapp
ansible webservers -m git -a “repo=git://foo.example.org/repo.git dest=/srv/myapp version=HEAD”
重启服务
ansible webservers -m service -a “name=httpd state=restarted”
后台执行命令,下面的是不获取返回信息
ansible all -B 3600 -P 0 -a “/usr/bin/long_running_operation --do-stuff”
配置文件
http://www.ansible.com.cn/docs/intro_configuration.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值