来自:入门小站
yaml
/etc/ansible/hosts
中配置命令模块
command
shell
文件模块
copy
fetch
file
安装模块
yum
服务模块
service
挂载模块
mount
定时任务
cron
用户模块
group
user
压缩解压
unarchive
> yum install ansible -y
> vim /etc/ansible/hosts
[web]
192.168.2.10 ansible_ssh_port=22 ansible_ssh_user=rumenz ansible_ssh_pass="123456"
192.168.2.11 ansible_ssh_port=22 ansible_ssh_user=rumenz ansible_ssh_pass="123456"
web
组(可以加很多主机),Ansible
默认使用的是ssh
协议,指定好端口,账号,密码就可以了。除了使用账号,密码的形式配置,我们也可以用秘钥,后面访问。> ansible web -m ping
web
就是上面我们定义的分组,-m
我后面指定模块,这里我们使用ping
模块,用于查看主机是否网络可达。Ansible
执行pwd
命令> ansible web -m shell -a "pwd"
shell
模块,-a
后面跟上需要执行的shell
命令Ansible
查看web
分组下nginx
服务是否在运行> ansible web -m shell -a "ps -ef | grep nginx"
Ansible
简单批量安装redis
> ansible web -m shell -a "yum install redis -y"
Ansible playbook
配置文件,更加灵活。END
官方站点:www.linuxprobe.com
Linux命令大全:www.linuxcool.com
刘遄老师QQ:5604241
Linux技术交流群:2261840
(新群,火热加群中……)
想要学习Linux系统的读者可以点击"阅读原文"按钮来了解书籍《Linux就该这么学》,同时也非常适合专业的运维人员阅读,成为辅助您工作的高价值工具书!