06Ansible角色
Ansible角色 roles是在ansible中,playbooks的目录组织结构。 而模块化之后,成为roles的组织结构,易读,代码可重用,层次清晰。 需求:通过role远程部署nginx并配置 准备目录结构 [root@ansible-server ~]# mkdir -p /tmp/roles/nginx/{files,handlers,tasks,templates,vars} [root@ansible-server ~]# touch /tmp/roles/site.yaml [root@ansible-server ~]# touch /tmp/roles/nginx/{handlers,tasks,vars}/main.yaml [root@ansible-server ~]# echo 1234 > roles/nginx/files/index.html [root@ansible-server ~]# yum install -y nginx && cp /etc/nginx/nginx.conf roles/nginx/templates/nginx.conf.j2 [root@ansible-server ~]# tree /tmp/roles/ /tmp/roles/ ├── nginx │ ├── files │ │ └── index.html