自动化运维ansible命令行

发布时间:2024-10-16 20:21:44 阅读:7次

自动化运维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=<crypted password here>"

下载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

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:自动化运维ansible命令行 出自老鄢博客 | 欢迎分享