主机上:
一、关闭selinux,关闭防火墙
vi /etc/selinux/config
修改disabled
systemctl stop firewalld
systemctl disable firewalld
二、安装:
yum install ansible -y
三、# 检查host key关闭和ansible日志启用
可以直接去ansible下的cfg文件中进行修改。
sed -i "s/\# host_key_checking = False/host_key_checking = False/g" /etc/ansible/ansible.cfg
sed -i "s/\# log_path = \/var\/log\/ansible.log/log_path = \/var\/log\/ansible.log/g" /etc/ansible/ansible.cfg
四、(免密码登录):
第一种:
#生成公钥
ssh-keygen -t rsa
#根据hosts用户组里密码相同的进行分发:
ansible all -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}' path=/root/.ssh/authorized_keys manage_dir=no" --ask-pass -c paramiko
或者
建立push.ssh.yaml文件:
前提是在hosts中将用户和密码设定。
- hosts: mytest
user: root
tasks:
- name: ssh-copy
authorized_key: user=tomcat key="{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"
tags:
- sshkey
最后ansible-playbook push.ssh.ymal 推送到个远程机器上。