ansible 笔记

  • CentOS7 安装 ansible
yum install ansible
  • 修改配置文件 /etc/ansible/ansible.conf
# 取消 ssh key 验证
host_key_checking = False
  • 修改配置文件 hosts
# 增加 tomcat 服务器组
[tomcat]
tomcat101 ansible_ssh_host=192.168.1.101
tomcat102 ansible_ssh_host=192.168.1.102
tomcat103 ansible_ssh_host=192.168.1.103
# 增加 mysql 服务器组
[mysql]
mysql201 ansible_ssh_host=192.168.1.201 ansible_ssh_pass=111111
mysql202 ansible_ssh_host=192.168.1.202
mysql203 ansible_ssh_host=192.168.1.203
# 全局设置全部服务器的默认设置
[all:vars]
ansible_ssh_port=22
ansible_ssh_user=root
ansible_ssh_pass=123456
  • authorized_key 模块
# 分发密钥
ansible all -m authorized_key -a "user=root key='{{ lookup('file', '/root/.ssh/id_rsa.pub') }}'"

猜你喜欢

转载自my.oschina.net/colben/blog/1785843