ansible-script模块使用方法

应用

在远程主机上执行ansible主机上的脚本,且不需要将脚本复制到被执行的远程主机上

参数

  • 脚本路径,必须参数
  • chdir:在执行脚本之前,先进入到指定目录
  • creates:当远程主机上的该文件存在时,不执行脚本;反之执行
  • removes:当远程主机上的该文件不存在时,不执行脚本;反之执行

示例

  1. 先进入/opt目录下,再执行test.sh脚本
]# ansible all -m script -a 'chdir=/opt /opt/test.sh'
  1. 若/opt/a.file存在时,不执行test.sh脚本
]# ansible all -m script -a 'creates=/opt/a.file /opt/test.sh'
  1. 若/opt/a.file不存在时,不执行test.sh脚本
]# ansible all -m script -a 'removes=/opt/a.file /opt/test.sh'

猜你喜欢

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