ansible: 项目实战
备注:
ansible-galaxy list 显示的是默认从网上下载的路径
# /usr/share/ansible/roles # /etc/ansible/roles
示例1: 批量安装httpd/
(1)创建文件目录
(2)创建roles/httpd/tasks,下面存放以下文件
- include: install.yml - include: config.yml - include: index.yml - include: start_service.yml
- name: config file copy: src=httpd.conf dest=/etc/httpd/conf/ backup=yes notify: restart
- name: install httpd
yum: name=httpd
- name: index.html
copy: src=index.html dest=/var/www/html/
- name: start serivce
service: name=httpd state=started enabled=yes
(3)创建roles/httpd/files 文件夹,存放我们配置文件
(4)创建roles/httpd/handles 文件夹,内存放main.yml
- name: restart
service: name=httpd state=restarted
(5) 在playbook中调用的角色,文件要和roles平级
--- # http role - hosts: testserver remote_user: root roles: -role:httpd
(6) 执行playbook
[root@zhu data]# ansible-playbook /data/roles_httpd.yml
人生苦短,我用Python