zoukankan      html  css  js  c++  java
  • 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 元字符 可以导致一个意外的命令被执行 如果
     
     引号没有正常完成 
    
  • 相关阅读:
    VS2003在解决方案范围内搜索卡死问题的解决
    文言古诗词
    中学名句
    Linux查看系统中socket状态
    为什么我希望用C而不是C++来实现ZeroMQ
    获取进程的IO计数
    Win7查看开关机记录
    VS的release工程设置为可调试
    VC开发中一些问题的解决
    shell脚本0——”一切皆文件“, 认识Shell
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349089.html
Copyright © 2011-2022 走看看