ansible安装基本使用

备注使用yum (centos7)
 
1. 安装
yum install -y ansible
2. 免密登录(ssh,最好使用dns 解析)
// create ssh key
ssh-keygen 
// copy ssh key to remote host
ssh-copy-id  -i /root/.ssh/id_rsa.pub root@remotehost
// test whether is ok
ssh root@remotehost

备注(参考dns 配置)

nano /etc/hosts
ip  dnsname
3. 配置ansible hosts
nano  /etc/ansible/hosts
[web]
dalongapp.demo
4. 简单测试命令
// 检查ansible 安装环境
ansible  all -m ping 

返回结果
dalongapp.demo | SUCCESS => {
    "changed": false, 
    "failed": false, 
    "ping": "pong"
}

备注:

all 代码所有主机  
m  为使用的module 
5. 帮助文档安装
可以通过安装ansible-doc 
yum install -y ansible-doc
6. 几个常用命令
a 执行命令
copy 复制文件
yum 安装包
user 添加用户
git git 下载代码
service  启动服务
setup 查看远程主机信息

posted on 2017-11-12 14:28  荣锋亮  阅读(223)  评论(0编辑  收藏  举报

导航