github安装(还有其他安装方法)
git clone git://github.com/ansible/ansible.git --recursive
cd ./ansible
- 复制ansible根目录中的examples目录下的ansible.cfg配置文件到/etc/ansible/目录下
cp examples/ansible.cfg /etc/ansible/
vim /etc/ansible/hosts
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"
}
网友评论