fenghzy 发表于 2015-9-16 08:53:58

Ansible 部署

  环境:
  vim /etc/hosts
  192.168.199.61 Ansible
  192.168.199.60 Nginx1
192.168.199.62 Nginx2
192.168.199.63 Haproxy

  在Ansible服务器上安装Ansible
  先解决依赖关系:
  # yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto# rpm –ivh

http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
  安装 Ansible
  yum –y install ansible
  通过安装 Ansible
  pip install ansbile pip
  配置/etc/hosts文件
  cat /etc/hosts
  
Nginx1
Nginx2
Haproxy

  配置ansible端能基于密钥认证的方式联系各被管理节点

ssh-keygen -t rsa -P ''
ssh-copy-id -i .ssh/id_rsa.pub root@Nginx1
ssh-copy-id -i .ssh/id_rsa.pub root@Nginx2
ssh-copy-id -i .ssh/id_rsa.pub root@Haproxy

  Ansible简单测试
  简单格式:ansible节点名称   [ -m模块]   -a命令参数
  举一个yum 配置的例子。
  执行
  # ansible all -m command -a 'curl -o /tmp/CentOS6-Base.repohttp://192.168.199.61/files/CentOS6-Base-163.repo'

  # ansible all -m copy -a 'src=/tmp/CentOS6-Base.repo dest=/etc/yum.repos.d/CentOS6-Base.repo'
  # 覆盖配置文件
页: [1]
查看完整版本: Ansible 部署