ansible模块-command模块shell模块script模块

本文详细介绍了Ansible中的command、shell和script模块的使用方法,包括基本用法、扩展应用和注意事项。command模块用于执行远程主机上的单一命令,支持chdir、creates、removes等参数。shell模块更为灵活,可以执行复杂的命令,而script模块则允许直接在控制器上运行脚本,无需先将其传输到远程主机。
摘要由CSDN通过智能技术生成

模块的应用语法格式:
    ansible 主机名称/主机组名称/主机地址信息/all  -m(指定应用的模块信息)  模块名称  -a(指定动作信息)  "执行什么动作"

 

命令类型模块:
    掌握第一个模块: command (默认模块)
    command – Executes a command on a remote node
              在一个远程主机上执行一个命令
    简单用法:
    [root@m01 scripts]# ansible 172.16.1.31 -m command -a "hostname"
    172.16.1.31 | CHANGED | rc=0 >>
    nfs01
  
    扩展应用:
    1) chdir      Change into this directory before running the command.
              在执行命令之前对目录进行切换
       ansible 172.16.1.31 -m command -a "chdir=/tmp touch oldboy.txt"

    2) creates    If it already exists, this step won't be run.
                如果文件存在了,不执行命令操作
       ansible 172.16.1.31 -m command -a "creates=/tmp/hosts touch oldboy.txt" 
       
    3) removes    If it already exists, this step will be run.
                如果文件存在了,    这个步骤将执行
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值