ansible 用户名密码

安装使用root权限

yum -y install ansible

创建ansible作为ansible的配置信息存储目录

mkdir ansible

进入目录

cd ansible

创建配置文件

vi hosts

[test]

yhq112 ansible_ssh_user=yhq ansible_ssh_pass=123456

说明

[test]   主机组,主机组下边可以包含多条主机信息

yhq112 主机组下的主机名

ansible_ssh_user  指定用户

ansible_ssh_pass 对应密码

查看主机列表

ansible test -i hosts --list-hosts

 

测试连通性

ansible test -i hosts -m ping

对指定的主机组远程执行命令

ansible test -i hosts -m command -a 'date' 

command模块下的命令

chdir 在执行命令之前,先切换到该目录

creates  一个文件名,当这个文件存在,则该命令不执行,可以用来做判断

removes  一个文件名,这个文件不存在,则该命令不执行

例如

#先切换到/app/ 目录,再执行“ls”命令

ansible test -i hosts -m command -a 'chdir=/app ls'

#如果/home/yhq/aaa.jpg存在,则不执行“ls”命令

ansible test -i hosts -m command -a 'creates=/home/yhq/aaa.jpg ls'

ansible test -i hosts -m command -a 'touch /home/yhq/aaa.jpg'

ansible test -i hosts -m command -a 'creates=/home/yhq/aaa.jpg ls'

 

 #如果/home/yhq/aaa.jpg存在,则执行“cat /home/yhq/st.sh”命令

ansible test -i hosts -m command -a 'removes=/home/yhq/aaa.jpg cat /home/yhq/st.sh'

远程执行脚本

ansible test -i hosts -m shell -a 'chdir=/home/yhq/hadoop-3.2.2/ sbin/stop-all.sh'

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值