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') }}'"

ansible 常用 roles

https://gitee.com/colben/ansible

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章