ansible安装(源码、centos6)
2017-04-08 本文已影响130人
快乐的涨姿势
github安装(还有其他安装方法)
- 下载
git clone git://github.com/ansible/ansible.git --recursive
cd ./ansible
- 复制ansible根目录中的examples目录下的ansible.cfg配置文件到/etc/ansible/目录下
cp examples/ansible.cfg /etc/ansible/
- 创建hosts文件
vim /etc/ansible/hosts
- 需要的python模块
sudo pip install paramiko PyYAML Jinja2 httplib2 six
- 启动
source ./hacking/env-setup
- 一旦运行env-setup脚本,就意味着Ansible从源码中运行起来了.默认的inventory文件是 /etc/ansible/hosts.inventory
$ echo "127.0.0.1" > ~/ansible_hosts
$ export ANSIBLE_HOSTS=~/ansible_hosts
SSH认证
- 在~/.ssh目录下生成钥id_rsa.pub(公钥)和id_rsa
ssh-keygen
# 然后一直回车
- 将公钥发到被管节点192.168.1.100的root用户下的.shh目录,生成authorized_keys
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.100
- 验证是否成功
ssh root@192.168.1.100
- 提示Failed to connect to the host via ssh
chown username: /home/username/.ssh
chown username: /home/username/.ssh/*
chmod 700 /home/username/.ssh
chmod 600 /home/username.ssh/*
验证
- 执行命令
ansible 192.168.1.100 -u root -m ping
- 返回结果
192.168.1.100 | SUCCESS => {
"changed": false,
"ping": "pong"
}