ansible-shell|command模块使用方法

应用

  1. shell模块在远程主机上执行shell命令,支持管道和重定向符号
  2. command模块在远程主机执行命令,不支持管道和重定向符号('<','>','|',';',&')

参数

  • 执行的命令,必要参数
  • chdir:在执行命令之前,先进入到指定目录
  • creates:当远程主机上的该文件存在时,不执行命令;反之执行
  • removes:当远程主机上的该文件不存在时,不执行命令;反之执行
  • executable:默认shell使用/bin/sh,可以指定其它类型shell,使用绝对路径

示例

  1. 进入到/opt目录下,更改test用户密码,此处用shell模块
]# ansible all -m shell -a 'chdir=/opt echo "123456"|passwd --stdin test'
  1. 进入到/opt目录下,执行ls命令,此处使用command模块
]# ansible all -m command -a 'chdir=/opt ls'

猜你喜欢

转载自www.cnblogs.com/wanwz/p/12929997.html