标签:use state led 地址 install log 脚本 res 自动
配置
1、vim /etc/anasible/hosts 加入IP地址并分组
[web]
192.168.1.101
192.168.1.102
192.168.1.103
[db]
192.168.1.[103:104] 表示192.168.1.103,192.168.1.104两台
192.168.1.105
[centos6]
192.168.1.101
192.168.1.102
[centos7]
192.168.1.103
192.168.1.104
192.168.1.105
2、vim /etc/ansible/ansible.cfg 查找首次登陆不不提示
host_key_checking = False 取消注释
log_path = /var/log/ansible 地址可以更改,取消注释,开启日志功能
3、ssh-keygen 密钥分发
ssh-copy-id 192.168.1.101 对于这步,服务器多,可以写脚本执行
ssh-copy-id 192.168.1.102
ssh-copy-id 192.168.1.103
ssh-copy-id 192.168.1.104
ssh-copy-id 192.168.1.105
ansible-playbook
handlers: 触发后的动作 notify:当顺序动作不执行时,触发该动作,自动触发
tags:标签,当需要只执行其中某个动作时使用 ansible-playbook -t install_httpd,copy_conf httpd.yml
limit:只执行主机名单中的某些主机,不用全部执行 ansible-playbook --limit ‘‘192.168.1.103 192.168.1.105" httpd.yml
httpd.yml
---
- hosts: centos7
remote_user: root
tasks:
- name: install httpd
tags: install_httpd
yum: name=httpd state=present
- name: copy conf file
copy: src=/app/httpd.conf dest=/etc/httpd/conf/ backup=yes
tags: copy_conf
notify: restart httpd
- name: start httpd
tags: start_httpd
service: name=httpd state=started enabled=yes
handlers:
- name: restart httpd
tags: restart_httpd
service: name=httpd state=restarted
标签:use state led 地址 install log 脚本 res 自动
原文地址:https://www.cnblogs.com/tony3154/p/10218670.html