自动化运维ansible命令行
首先要免密
然后在`/etc/ansible/hosts`中设置host主机
```
tr@tr-desktop:~$ cat /etc/ansible/hosts
[host1]
10.1.8.56
[host2]
127.0.0.1
```
以下为操作命令
检查ansible安装环境
```
tr@tr-desktop:~$ ansible all -m ping -u tr
```
执行命令
```
tr@tr-desktop:~$ ansible all -a "/bin/echo hello"
```
复制文件
```
tr@tr-desktop:~$ ansible all -m copy -a "src=/etc/hosts dest=/tmp/hosts"
```
安装包
```
tr@tr-desktop:~$ ansible all -u root -m apt -a "name=acme state=present"
```
添加用户
```
ansible all -m user -a "name=foo password=
```
下载git
```
ansible all -m git -a "repo=git://foo.example.org/repo.git dest=/srv/myapp version=HEAD"
```
启动服务
```
ansible all -m service -a "name=httpd state=started"
```
并发执行
```
ansible all -a "/sbin/reboot" -f 10
```
查看远程主机的全部系统信息
```
ansible all -m setup
```