• ansible command模块


    
    ansible command 模块:
    
    command - Executes a command on a remote node
    
    在一个远程主机上执行一个命令:
    
    简介:
    
    command 模块接收command 名字跟着空格分隔的参数列表
    
    [esb@esbapp1 sbin]$ ./ansible -i esbhosts esbapp2 -m command -a 'id'
    1.1.1.1 | SUCCESS | rc=0 >>
    uid=501(esb) gid=501(esbgrp) 组=501(esbgrp)
    
    给定的命令 会在所有选择的节点上执行。 它不会通过shell进行处理,因此变量像$HOME和操作像 
    
     "<", ">", "|", ";" and "&"  不能工作(使用shell 模块 如果你需要那些功能)
     
     
     参数
     
     argv 
    (added in 2.6
    
    允许用户提供命令作为一个列表 
    
    chdir  
    
    在运行命令前 改变目录
    
    [esb@esbapp1 sbin]$ ssh esbapp2 "cat /tmp/aaa"
    cat: /tmp/aaa: 没有那个文件或目录
    [esb@esbapp1 sbin]$ 
    [esb@esbapp1 sbin]$ ./ansible -i esbhosts esbapp2 -m command -a 'touch aaa chdir=/tmp'
     [WARNING]: Consider using file module with state=touch rather than running touch
    
    1.1.1.1 | SUCCESS | rc=0 >>
    
    
    [esb@esbapp1 sbin]$ ssh esbapp2 "cat /tmp/aaa"
    [esb@esbapp1 sbin]$ 
    
    
    creates:
    
    一个文件名 当他存在时.这个步骤不会运行
    
    [esb@esbapp1 sbin]$ ./ansible -i esbhosts esbapp2 -m command -a 'hostname creates=/tmp/aaa'
    1.1.1.1 | SUCCESS | rc=0 >>
    skipped, since /tmp/aaa exists
    
    [esb@esbapp1 sbin]$ ./ansible -i esbhosts esbapp2 -m command -a 'hostname creates=/tmp/bbb'
    1.1.1.1 | SUCCESS | rc=0 >>
    esbapp2
    
    free_form
    
    command 模块使用一种自由格式命令来运行 
     
     
     注意:
     
     如果你需要运行 命令行通过shell( 比如说你使用  <, >, |, etc), 
     
     你实际需要shell模块代替, 解析shell 元字符 可以导致一个意外的命令被执行 如果
     
     引号没有正常完成 
    
  • 相关阅读:
    C语言|作业07
    Cookie应用
    刷新页面,怎么做到不提示“不重新发送消息,则无法刷新页面”
    笔记
    笔记
    元素内部设定position
    企业微信正式发布 Tita 绩效宝,助力企业完成数字化绩效管理转型
    OKR实践:如何获得高层的理解与关注
    OKR:衡量结果和解决实际问题
    2022 年绩效评估,HR看这一篇就够了!
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349089.html
Copyright © 2020-2023  润新知