DO447利用推荐做法进行开发–章节实验
RHCSA专栏:戏说 RHCSA 认证
RHCE专栏:戏说 RHCE 认证
此文章(第一章 利用推荐做法进行开发–章节实验 )收录在RHCA专栏:RHCA 回忆录
[student@workstation ~]$ lab development-review start
📑按要求拉取代码并进入代码目录
[student@workstation ~]$ cd git-repos
[student@workstation git-repos]$ git clone http://git.lab.example.com:8081/git/development-review.git
Cloning into 'development-review'...
remote: Enumerating objects: 53, done.
remote: Counting objects: 100% (53/53), done.
remote: Compressing objects: 100% (35/35), done.
remote: Total 53 (delta 5), reused 0 (delta 0)
Unpacking objects: 100% (53/53), done.
[student@workstation git-repos]$ cd development-review
📑验证代码剧本准确性
[student@workstation development-review]$ ansible-playbook site.yml
[student@workstation development-review]$ curl http://servera
This is serverb.lab.example.com. (version v1.0)
[student@workstation development-review]$ curl http://servera
This is serverc.lab.example.com. (version v1.0)
[student@workstation development-review]$ curl http://servera
This is serverb.lab.example.com. (version v1.0)
[student@workstation development-review]$ curl http://servera
This is serverc.lab.example.com. (version v1.0)
📑修改角色目录名称
[student@workstation development-review]$ cd roles/
[student@workstation roles]$ ls
firewall haproxy my_role webapp
[student@workstation roles]$ mv -v my_role apache
renamed 'my_role' -> 'apache'
[student@workstation roles]$ cd ..
[student@workstation development-review]$ vim deploy_apache.yml
- name: Ensure Apache is deployed
hosts: web_servers
force_handlers: True
gather_facts: no
roles:
# The "apache" role has a dependency
# on the "firewall" role. The
# "firewall" role requires a
# "firewall_rules" variable be defined.
- role: apache
firewall_rules:
# Allow http requests from the
# internal zone.
- zone: internal
service: http
# Add the load balancer IP to
# the internal zone.
- zone: internal
source: 172.25.250.10
# 可使用 %s#my_role#apache#g 进行查找替换
📑运行测试
[student@workstation development-review]$ ansible-playbook deploy_apache.yml
📑提交改变的代码
[student@workstation development-review]$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: deploy_apache.yml
deleted: roles/my_role/meta/main.yml
deleted: roles/my_role/tasks/main.yml
deleted: roles/my_role/vars/main.yml
Untracked files:
(use "git add <file>..." to include in what will be committed)
roles/apache/
no changes added to commit (use "git add" and/or "git commit -a")
[student@workstation development-review]$ git rm roles/my_role/*
rm 'roles/my_role/meta/main.yml'
rm 'roles/my_role/tasks/main.yml'
rm 'roles/my_role/vars/main.yml'
[student@workstation development-review]$ git add roles/apache
[student@workstation development-review]$ git add deploy_apache.yml
[student@workstation development-review]$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: deploy_apache.yml
renamed: roles/my_role/meta/main.yml -> roles/apache/meta/main.yml
renamed: roles/my_role/tasks/main.yml -> roles/apache/tasks/main.yml
renamed: roles/my_role/vars/main.yml -> roles/apache/vars/main.yml
[student@workstation development-review]$ git commit -m "Renamed my_role role to apache."
[master ad25d92] Renamed my_role role to apache.
4 files changed, 2 insertions(+), 2 deletions(-)
rename roles/{
my_role => apache}/meta/main.yml (100%)
rename roles/{
my_role => apache}/tasks/main.yml (100%)
rename roles/{
my_role => apache}/vars/main.yml (100%)
[student@workstation development-review]$ git push
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 392 bytes | 392.00 KiB/s, done.
Total 4 (delta 3), reused 0 (delta 0)
To http://git.lab.example.com:8081/git/development-review.git
19d8b5e..ad25d92 master -> master
📑完善剧本的要素
[student@workstation development-review]$ cat deploy_webapp.yml
- name: Ensure the web application is deployed
hosts: web_servers
gather_facts: no
vars:
version: v1.0
message: "This is {
{ inventory_hostname }}."
roles:
- role: webapp
[student@workstation development-review]$ cat roles/webapp/tasks/main.yml
---
# tasks file for webapp
- name: Ensure placeholder content is deployed
copy:
content: "{
{ message }} (version {
{ version }})\n"
dest: /var/www/html/index.html
📑运行测试
[student@workstation development-review]$ ansible-playbook deploy_webapp.yml
📑提交改变的代码
[student@workstation development-review]$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: deploy_webapp.yml
modified: roles/webapp/tasks/main.yml
no changes added to commit (use "git add" and/or "git commit -a")
[student@workstation development-review]$ git add deploy_webapp.yml
[student@workstation development-review]$ git add roles/webapp/*
[student@workstation development-review]$ git commit -m "Added names to webapp playbook and role."
[master 5145179] Added names to webapp playbook and role.
2 files changed, 4 insertions(+), 2 deletions(-)
[student@workstation development-review]$ git push
Enumerating objects: 13, done.
Counting objects: 100% (13/13), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (7/7), 753 bytes | 753.00 KiB/s, done.
Total 7 (delta 3), reused 0 (delta 0)
To http://git.lab.example.com:8081/git/development-review.git
ad25d92..5145179 master -> master
📑按要求修改变量名称
[student@workstation development-review]$ cat roles/webapp/tasks/main.yml
---
# tasks file for webapp
- name: Ensure placeholder content is deployed
copy:
content: "{
{ webapp_message }} (version {
{ webapp_version }})\n"
dest: /var/www/html/index.html
[student@workstation development-review]$ cat roles/webapp/defaults/main.yml
webapp_version: v1.0
webapp_message: "This is {
{ inventory_hostname }}."
[student@workstation development-review]$ cat deploy_webapp.yml
- name: Ensure the web application is deployed
hosts: web_servers
gather_facts: no
vars:
webapp_version: v1.0
webapp_message: "This is {
{ inventory_hostname }}."
roles:
- role: webapp
📑运行测试
[student@workstation development-review]$ ansible-playbook deploy_webapp.yml
📑提交改变的代码
[student@workstation development-review]$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: deploy_webapp.yml
modified: roles/webapp/defaults/main.yml
modified: roles/webapp/tasks/main.yml
no changes added to commit (use "git add" and/or "git commit -a")
[student@workstation development-review]$ git add deploy_webapp.yml
[student@workstation development-review]$ git add roles/webapp/*
[student@workstation development-review]$ git commit -m "Updated webapp role variable names."
[master 30ee0ab] Updated webapp role variable names.
3 files changed, 5 insertions(+), 5 deletions(-)
[student@workstation development-review]$ git push
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (9/9), 790 bytes | 790.00 KiB/s, done.
Total 9 (delta 4), reused 0 (delta 0)
To http://git.lab.example.com:8081/git/development-review.git
5145179..30ee0ab master -> master
📑再次运行总测试
[student@workstation development-review]$ ansible-playbook site.yml
📑评分并清除实验
[student@workstation development-review]$ lab development-review grade
[student@workstation development-review]$ lab development-review finish
💡总结
RHCA认证经历5门的考试,还是需要花不少时间去学习与备考的,好好加油,可以噶🤪。
以上就是【金鱼哥】对 第一章 利用推荐做法进行开发–章节实验 的简述和讲解。希望能对看到此文章的小伙伴有所帮助。
如果这篇【文章】有帮助到你,希望可以给【金鱼哥】点个赞👍,创作不易,相比官方的陈述,我更喜欢用【通俗易懂】的文笔去讲解每一个知识点,如果有对【运维技术】感兴趣,也欢迎关注❤️❤️❤️ 【金鱼哥】❤️❤️❤️,我将会给你带来巨大的【收获与惊喜】💕💕!