百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术文章 > 正文
ansible常用命令_ansible命令参数

ansible常用命令_ansible命令参数

  • 网站名称:ansible常用命令_ansible命令参数
  • 网站分类:技术文章
  • 收录时间:2025-10-13 18:14
  • 网站地址:

进入网站

“ansible常用命令_ansible命令参数” 网站介绍

有192.168.1.1-192.168.1.4,四台服务器

ansible安装完成后,可以修改/etc/ansible/hosts,添加

[web_cluster]
192.168.1.[1:4]
[web_cluster:vars]
ansible_ssh_user=web
ansible_ssh_pass=123456
ansible_become_user=root
ansible_become_pass=123456
ansible_become_method=su

该配置的意思是将这4台服务器取个名字叫web_cluster, ansible使用web/123456操作,不过ansible转换为root进行操作

比如jdk的安装包已经上传到192.168.1.1,路径为
/opt/jdk-8u144-linux-x64.rpm

#分发jdk安装包,使用该命令将jdk分发到四台机器上

ansible web_cluster -m copy -a 'src=/opt/jdk-8u144-linux-x64.rpm dest=/opt/' -b &&

#安装jdk

ansible web_cluster -m shell -a 'cd /opt;rpm -ivh jdk-8u144-linux-x64.rpm' -b &&

#分发jdk安装包

ansible web_cluster -m copy -a 'src=/home/web/webapp.zip dest=/home/web' -b &&

#解压项目zip包

ansible web_cluster -m shell -a 'cd /home/web/;unzip webapp.zip' -b &&

#修改配置文件的运行环境参数

ansible web_cluster -m replace -a 'path=/home/web/webapp/application.yml regexp="test" replace=prod' -b &&

#启动web

ansible web_cluster -m shell -a 'cd /home/web/webapp/;./start.sh' -b &&