远程执行命令

1、修改配置文件
# vim /etc/ansible/hosts
[testhosts]
127.0.0.1
192.168.32.105

2.执行 command 模块
ansible testhosts -m command -a 'w'
ansible 127.0.0.1 -m command -a 'hostname'

3、报错缺少  libselinux-python
yum -y install libselinux-python

4、用 shell 来执行
ansible slave-puppet.zjcap.cn -m shell -a 'hostname'
ansible slave-puppet.zjcap.cn -m shell -a 'cat /etc/passwd| grep root' 支持管道

你可能感兴趣的:(远程执行命令)