ansible☞常用模块-命令调用

阅读量: zyh 2020-04-20 17:56:00
Categories: > Tags:

shell

远程执行一个命令

部分参数解析:

chdir 远程工作目录

executable 远程执行shell,需要绝对路径

ansible localhost -m shell -a "chdir=/ ls"
localhost | CHANGED | rc=0 >>
bin
boot
dev
etc
home
...

script

远程执行一个ansible主机环境的脚本

部分参数解析:

chdir 远程工作目录

cat test.sh
#!/bin/bash
for i in `ls /export`;do
        echo $i
done
#-------------
ansible -i hosts test -m script -a "/home/zyh/test.sh"
10.200.10.212 | CHANGED => {
    "changed": true, 
    "rc": 0, 
    "stderr": "Shared connection to 10.200.10.212 closed.\r\n", 
    "stderr_lines": [
        "Shared connection to 10.200.10.212 closed."
    ], 
    "stdout": "jdk1.8.0_191\r\njdk8\r\nsen\r\n", 
    "stdout_lines": [
        "jdk1.8.0_191", 
        "jdk8", 
        "sen"
    ]
}