ansible(十)roles

1、roles:角色的集合

 1 [root@linux-node1 ~]# tree ansible/
 2 ansible/
 3 ├── nginx_roule.yml
 4 └── roles
 5     ├── httpd
 6     ├── memcache
 7     ├── mysql
 8     └── nginx
 9         ├── tasks
10         │?? ├── group.yml
11         │?? ├── main.yml
12         │?? ├── restart.yml
13         │?? ├── start.yml
14         │?? ├── templ.yml
15         │?? ├── user.yml
16         │?? └── yum.yml
17         └── templates
18             └── nginx.conf.j2
roles目录
[root@linux-node1 ansible]# cat nginx_roule.yml 
- hosts: date
  remote_user: root
  roles:
    - role: nginx
[root@linux-node1 tasks]# cat main.yml 
- include: group.yml
- include: user.yml
- include: yum.yml
- include: templ.yml
- include: start.yml
[root@linux-node1 tasks]# cat group.yml 
- name: create group
  group: name=nginx
[root@linux-node1 tasks]# cat user.yml 
- name: create user
  user: name=nginx group=nginx
[root@linux-node1 tasks]# cat yum.yml 
- name: install package
  yum: name=nginx
[root@linux-node1 tasks]# cat templ.yml 
- name: copy conf
  template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
[root@linux-node1 tasks]# cat start.yml 
- name: start service
  service: name=nginx state=started enabled=yes
[root@linux-node1 tasks]# cat restart.yml 
- name: start service
  service: name=nginx state=restarted enabled=yes

posted @ 2020-01-02 16:35  随心朝阳  阅读(220)  评论(0编辑  收藏  举报