3-ansible command模块

ansible command模块为ansible默认模块,主要用于执行linux基础命令,可以执行远程服务器命令执行、任务执行等操作。command模块使用详解:

chdir                执行命令前,切换到目录;
creates              当该文件存在时,则不执行该步骤;
executable           换用shell环境执行命令;
free_form            需要执行的脚本,就是常用的形式;
removes              当该文件不存在时,则不执行该步骤;
warn                 如果在ansible.cfg中存在告警,如何设定了false,不会警告此行;

1.ansible command命令执行

ansible -i /etc/ansible/hosts all -m command -a "date"
[root@cent79-2 ansible]# ansible -i /etc/ansible/hosts all -m command -a "date"
192.168.10.100 | CHANGED | rc=0 >>
Tue Mar 31 10:10:48 CST 2026
[root@cent79-2 ansible]# 

2.ansible command远程执行ping命令

ansible all -m command -a "ping -c 1 192.168.10.100"
[root@cent79-2 ansible]# ansible all -m command -a "ping -c 1 192.168.10.100"
192.168.10.100 | CHANGED | rc=0 >>
PING 192.168.10.100 (192.168.10.100) 56(84) bytes of data.
64 bytes from 192.16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黑要上天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值