roles function of ansible (v)

Source: Internet
Author: User
Tags vars

Easy to use roles for large projects

Directory structure Orchestration

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/8C/36/wKiom1hlF-SjFR-QAAHrlrracRc046.png-wh_500x0-wm_3 -wmp_4-s_1176155170.png "title=" 1.png "alt=" Wkiom1hlf-sjfr-qaahrlrracrc046.png-wh_50 "/>

One click to install HTTPD and provide service

Create a directory structure

[[email protected] ansible]# mkdir-p Roles/httpd/{tasks,files,vars}

[Email protected] ansible]# CD Roles/httpd/tasks

[[email protected] roles] #touch httpd/{files/main.yml,tasks/{groupadd.yml,install.yml,main.yml,restart.yml, USERADD.YML},VARS/MAIN.YML}

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/8C/32/wKioL1hlGAPC6d7dAAAWn-l58cw101.png-wh_500x0-wm_3 -wmp_4-s_2326024754.png "title=" 2.png "alt=" Wkiol1hlgapc6d7daaawn-l58cw101.png-wh_50 "/>

The directory structure is created, and then you start to configure

[Email protected] ~]# Cd/root/ansible/roles/httpd/tasks

First configure MAIN.YML to include all of the configuration in

[email protected] tasks]# cat Main.yml

---

-Include:groupadd.yml

-Include:useradd.yml

-Include:install.yml

-Include:restart.yml

Configure Add user groups

[email protected] tasks]# cat Groupadd.yml

---

-Name:add Group httpd

Group:name=web state=present

Configure Add Users

[email protected] tasks]# cat Useradd.yml

---

-Name:add Group httpd

USER:NAME=HTTPD Groups=web System=yes state=present

Configuring the Installation httpd

[email protected] tasks]# cat Install.yml

---

-Name:install HTTPD

YUM:NAME=HTTPD state=present

Configuring Restart HTTPd

[email protected] tasks]# cat Restart.yml

---

-Name:restart HTTPD

SERVICE:NAME=HTTPD state=restarted

Configuring the primary Yml file

[Email protected] roles]# pwd

/root/ansible/roles

[email protected] roles]# cat Installhttpd.yml

---

-Hosts:test

Remote_user:root

Roles

-ROLE:HTTPD

Test

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M01/8C/32/wKioL1hlGDGyYvrVAABJ4zKZS1Q115.png-wh_500x0-wm_3 -wmp_4-s_3161819666.png "style=" Float:none; "title=" 3.png "alt=" Wkiol1hlgdgyyvrvaabj4zkzs1q115.png-wh_50 "/>

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/8C/36/wKiom1hlGDLxN-uzAABcJ2oXM1U514.png-wh_500x0-wm_3 -wmp_4-s_471239153.png "style=" Float:none; "title=" 4.png "alt=" Wkiom1hlgdlxn-uzaabcj2oxm1u514.png-wh_50 "/>

Provide configuration Web site files

[Email protected] files]# pwd

/root/ansible/roles/httpd/files

[email protected] files]# cat index.html

Create a file for the copy module

[email protected] tasks]# cat Filecp.yml

---

-NAME:CP Documentfile

Copy:src=index.html dest=/var/www/html/index.html

Include file to main

[email protected] tasks]# cat Main.yml

---

-Include:groupadd.yml

-Include:useradd.yml

-Include:install.yml

-Include:restart.yml

-Include:filecp.yml

Test:

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/8C/32/wKioL1hlGEeyQRC5AABoCL_CzYc798.png-wh_500x0-wm_3 -wmp_4-s_1494781897.png "title=" 5.png "alt=" Wkiol1hlgeeyqrc5aabocl_czyc798.png-wh_50 "/>

Roles can also reference

Cases:

[Email protected] roles]# pwd

/root/ansible/roles

[email protected] roles]# CP HTTPD/NGINX-RF

[Email protected] roles]# CD nginx/tasks/

[Email protected] tasks]# RM-RF *

[Email protected] roles]# CD nginx/tasks/

[email protected] tasks]# cat Main.yml

---

-Include:httpd/tasks/restart.yml

[email protected] roles]# CP installhttpd.yml INSTALLNGINX.YML

[email protected] roles]# cat Installnginx.yml

---

-Hosts:test

Remote_user:root

Roles

-Role:nginx

Test:

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8C/36/wKiom1hlGGGSv4m5AAAxcfFki-8847.png-wh_500x0-wm_3 -wmp_4-s_3524004701.png "title=" 11.png "alt=" Wkiom1hlgggsv4m5aaaxcffki-8847.png-wh_50 "/>

Expand:

1. Execute multiple roles at once

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/8C/36/wKiom1hlGHvxmBGnAAAVX8Llvik818.png-wh_500x0-wm_3 -wmp_4-s_3986092922.png "title=" 22.png "alt=" Wkiom1hlghvxmbgnaaavx8llvik818.png-wh_50 "/>

2, the roles to label, can be executed separately

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/8C/32/wKioL1hlGIizmAwoAAAYgSuYthY638.png-wh_500x0-wm_3 -wmp_4-s_1703512455.png "title=" 33.png "alt=" Wkiol1hlgiizmawoaaaygsuythy638.png-wh_50 "/>

Test

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/8C/32/wKioL1hlGJvjcnqmAAAyb2X2HYo500.png-wh_500x0-wm_3 -wmp_4-s_3853290365.png "title=" 44.png "alt=" Wkiol1hlgjvjcnqmaaayb2x2hyo500.png-wh_50 "/>

3. Multi-label

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/8C/36/wKiom1hlGLKASxGmAAAznxhViSQ830.png-wh_500x0-wm_3 -wmp_4-s_1410484183.png "title=" 555.png "alt=" Wkiom1hlglkasxgmaaaznxhvisq830.png-wh_50 "/>

To execute a Web project

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/8C/32/wKioL1hlGMLTPfB5AABzXBheCLY179.png-wh_500x0-wm_3 -wmp_4-s_4086162261.png "title=" 121.png "alt=" Wkiol1hlgmltpfb5aabzxbhecly179.png-wh_50 "/>








This article from "Char" blog, declined reprint!

roles function of ansible (v)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.