Ansible(一) 安装与简单测试

安装

 #安装阿里云epel

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

#安装ansible

yum install ansible -y

测试

生成密钥,密码为空

ssh-keygen -t rsa -P ""

将公钥上传至指定服务器

ssh-copy-id -i ~/.ssh/id_rsa.pub user@192.168.255.140

配置/etc/ansible/hosts文件,添加一行

192.168.255.140

测试

ansible all -m ping 

指定用户,节点服务器要有这个用户

ansible all -m ping -u bruce

对节点运行命令

ansible all -a  "/bin/echo hello"

ansible all -a "uname -a"

原文地址:https://www.cnblogs.com/coolruo/p/14299011.html