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
main.yml
- name: config file
  copy: src=httpd.conf dest=/etc/httpd/conf/ backup=yes
  notify: restart
config
- name: install httpd
  yum: name=httpd
install.yml
- name: index.html
  copy: src=index.html dest=/var/www/html/
index.yml
- name: start serivce
  service: name=httpd state=started enabled=yes
start_serivce.yml

 

(3)创建roles/httpd/files 文件夹,存放我们配置文件

(4)创建roles/httpd/handles 文件夹,内存放main.yml

- name: restart
  service: name=httpd state=restarted
main.yml

 

 

 

 

 

 

 (5) 在playbook中调用的角色,文件要和roles平级

 

 

 

---
# http role
- hosts: testserver
  remote_user: root

  roles:
    -role:httpd
roles_httpd.yml

(6) 执行playbook

[root@zhu data]# ansible-playbook /data/roles_httpd.yml

 

posted on 2021-02-24 12:10  超nmmmmm  阅读(116)  评论(0编辑  收藏  举报

导航