官术网_书友最值得收藏!

Ansible roles

While playbooks offer a great way to execute plays in a pre-defined order, there is a brilliant feature on Ansible that takes the whole idea to a completely different level. Roles are a convenient way to bundle tasks, supporting assets such as files and templates, coupled with an automatic set of search paths.

By using a concept most programmers would be familiar with, of including files and folders and ascribing what is being included, a playbook becomes infinitely more readable and understandable. Roles are basically made up of tasks, handlers, and configurations, but by adding an additional layer to how a playbook is structured, we can easily get the big picture overview as well as the low-level details. 

This allows for reusable code and a pision of work in a team tasked with writing playbooks. For example, the database guru writes a role (almost like a partial playbook) for setting up the database and the security guru writes one on hardening such a database.

While it is possible to write a playbook in one very large file, eventually you want to reuse files and start to organize things.

Large and complex playbooks are hard to maintain and it is very difficult to reuse sections of a large playbook. Breaking a playbook into roles allows very efficient code reuse and makes playbooks much easier to understand.

The benefits of using roles while building large playbooks include:

  • Collaborating on writing playbooks
  • Reusing existing roles
  • Roles can be updated, improved upon independently
  • Handling variables, templates, and files is easier

LAMP usually stands for Linux, Apache, MySQL, PHP. A popular combination of software that is used to build applications for the web. Nowadays, another common combination in the PHP world is LEMP, which is Linux, NGINX, MySQL, PHP.

This is an example of what a possible LAMP stack site.yml can look like:

- name: LAMP stack setup on ubuntu 16.04
hosts: all
gather_facts: False
remote_user: "{{remote_username}}"
become: yes

roles:
- common
- web
- db
- php

Note the list of roles. Just by reading the role names we can get an idea of the kind of tasks possibly under that role. 

主站蜘蛛池模板: 陈巴尔虎旗| 榆树市| 城口县| 马龙县| 台山市| 邳州市| 革吉县| 吉林省| 黄龙县| 如皋市| 繁峙县| 炉霍县| 龙南县| 望谟县| 额济纳旗| 富锦市| 吐鲁番市| 曲麻莱县| 彭泽县| 荔波县| 北辰区| 始兴县| 永善县| 财经| 南皮县| 静安区| 仙居县| 集安市| 南丰县| 濮阳市| 二连浩特市| 阿拉善左旗| 贡山| 太仆寺旗| 海原县| 万山特区| 县级市| 延吉市| 屏东市| 新兴县| 绥芬河市|