Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Ansible role Management-Roles (example demonstration!!)

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

An overview of Roles Roles can automatically load variable files, task, handlers, and so on, based on a hierarchical structure. To put it simply, Roles is simply by placing variables, files, tasks, modules, and processors in separate directories, and you can easily include them. Roles is generally used in scenarios where services are built on hosts, but it can also be used in scenarios such as building daemons. Roles directory name specific meaning files is used to store files called by copy module or script module templates is used to store j regular templates, template module will automatically look for regular template files tasks in this directory this directory should contain a main.yml file, which should be used to define the task list for this role, this file can use include to contain other task files located in this directory handlers this directory should contain a main.yml file This directory should contain a main.yml file to define the variables used in this role, defaults, and this directory should contain a main.yml file for setting the default variable meta for the current role. This directory should contain a main.yml file. To define the special settings for this role and its dependencies to use Roles in playbook to create a directory with the roles command # by default, mkdir / etc/ansible/roles/-p creates a global variable directory, mkdir / etc/ansible/group_vars/-ptouch / etc/ansible/group_vars/all# file name, when referencing, be careful to create a directory with the name of each role in the roles directory For example, httpdmkdir / etc/ansible/roles/common-p creates files, handlers, tasks, templates, meta, defaults and vars directories in the directory of each role command. Directories that are not needed can be created as empty directories. However, it is necessary to create mkdir / etc/ansible/roles/httpd/ {files,templates,tasks,handlers,vars,defaults,meta}-pmkdir / etc/ansible/roles/mysql/ {files,templates,tasks,handlers,vars,defaults,meta}-p to create main.yml files in the handlers, tasks, meta, defaults, vars directories of each role. Never customize touch / etc/ansible/roles/httpd/ {defaults,vars,tasks,meta,handlers} / main.ymltouch / etc/ansible/roles/mysql/ {defaults,vars,tasks,meta,handlers} / main.yml in the playbook file Call each role vim / etc/ansible/site.yml- hosts: webserver remote_user: root roles:-httpd-mysql to install and build LAMP architecture instance demonstration to create service component working directory mkdir / etc/ansible/roles/httpd/ {files,templates,tasks,handlers,vars,defaults,meta}-pmkdir / etc/ansible/roles/mysql/ {files,templates,tasks,handlers,vars,defaults,meta}-pmkdir / etc/ansible/roles/php/ {files,templates,tasks,handlers,vars,defaults Meta}-p create an empty yml file touch / etc/ansible/roles/httpd/ {defaults,vars,tasks,meta,handlers} / main.ymltouch / etc/ansible/roles/mysql/ {defaults,vars,tasks,meta,handlers} / main.ymltouch / etc/ansible/roles/php/ {defaults,vars,tasks,meta Handlers} / main.yml write httpd module # write a simple tasks/main.ymlvim / etc/ansible/roles/httpd/tasks/main.yml- name: ensure apache is at the latest version yum: pkg= {{pkg}} state=latest# define variables, which can be defined in global variables Can also be defined in the roles role variable Generally defined in role variables vim / etc/ansible/roles/httpd/vars/main.ymlpkg: httpd write mysql module vim / etc/ansible/roles/mysql/tasks/main.yml- name: ensure mysql is at the latest version yum: pkg= {{pkg}} state=latest# definition variable vim / etc/ansible/roles/mysql/vars/main.ymlpkg: mariadb* write php module vim / etc/ansible/roles/php/tasks/main.yml- name: ensure php is at the latest version Yum: pkg= {{pkg}} state=latest# definition variable vim / etc/ansible/roles/php/vars/main.ymlpkg: php* Writing roles instance vim / etc/ansible/site.yml- hosts: webserver remote_user: root roles:-httpd-mysql-php# execution script ansible-playbook site.yml is executed on the remote host after execution Query to verify whether the specified service installs rpm-Q httpdhttpd-2.4.6-90.el7.centos.x86_64rpm-Q mariadbmariadb-5.5.64-1.el7.x86_64rpm-Q phpphp-5.4.16-46.1.el7_7.x86_64. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report