当前位置: 首页 > news >正文

RHCA---DO477---变量实验

实验目的如下:

1. 环境准备: 使用命令lab inventory-variables start初始化环境
2. 进入/home/student/git-repos目录克隆下载http://git.lab.example.com:8081/git/inventory-variables.git
3. 将目录下yaml文件内容以group_vars形式修改
4. 部署并将修改后ansible-playbook代码上传git仓库
5. 环境结束使用lab inventory-variables finish清理环境

试验开始

cd /home/student/git-repos
git clone http://git.lab.example.com:8081/git/inventory-variables.git
cd inventory-variables/=====================
确认2个组名
grep hosts deploy_haproxy.yml  deploy_webapp.yml
====得到以下内容:
deploy_haproxy.yml:  hosts: lb_servers
deploy_webapp.yml:  hosts: web_servers
创建目录
mkdir group_vars/{lb_servers,web_servers} -p

此时deploy_haproxy.yml 内容如下.

[student@workstation inventory-variables (master)]$cat deploy_haproxy.yml
- name: Ensure HAProxy is deployedhosts: lb_serversforce_handlers: Trueroles:# The "haproxy" role has a dependency on the "firewall" role.# The "firewall" role requires a "firewall_rules" variable be defined.- role: haproxyfirewall_rules:# Allow 80/tcp connections- port: 80/tcphaproxy_appservers:- name: serverb.lab.example.comip: 172.25.250.11backend_port: 80- name: serverc.lab.example.comip: 172.25.250.12backend_port: 80

将以下内容放入group_vars/lb_servers/firewall.yml中

firewall_rules:# Allow 80/tcp connections- port: 80/tcp

将以下内容放入group_vars/lb_servers/haproxy.yml中(其实这里路径对即可,文件名可以不严格安装这个,只是好识别)

haproxy_appservers:- name: serverb.lab.example.comip: 172.25.250.11backend_port: 80- name: serverc.lab.example.comip: 172.25.250.12backend_port: 80

然后删除deploy_haproxy.yml中的这部分内容,此时deploy_haproxy.yml如下:

- name: Ensure HAProxy is deployedhosts: lb_serversforce_handlers: Trueroles:# The "haproxy" role has a dependency on the "firewall" role.# The "firewall" role requires a "firewall_rules" variable be defined.- role: haproxy

deploy_apache内容如下:

- name: Ensure Apache is deployedhosts: web_serversforce_handlers: Trueroles:# The "apache" role has a dependency on the "firewall" role.# The "firewall" role requires a "firewall_rules" variable be defined.- role: apachefirewall_rules:# Allow http requests from the load_balancer.- zone: internalservice: httpsource: "172.25.250.10"

将以下内容放入group_vars/web_servers/firewall.yml中

firewall_rules:# Allow http requests from the load_balancer.- zone: internalservice: httpsource: "172.25.250.10"

再将源文件这部分内容删除,此时deploy_apache.yml内容如下

- name: Ensure Apache is deployedhosts: web_serversforce_handlers: Trueroles:# The "apache" role has a dependency on the "firewall" role.# The "firewall" role requires a "firewall_rules" variable be defined.- role: apache

执行命令ansible-playbook site.yml运行部署

[student@workstation inventory-variables (master *%)]$ansible-playbook site.ymlPLAY [Ensure HAProxy is deployed] ******************************************************TASK [Gathering Facts] *****************************************************************
ok: [servera.lab.example.com]TASK [firewall : Ensure Firewall Sources Configuration] ********************************
ok: [servera.lab.example.com] => (item={'port': '80/tcp'})TASK [haproxy : Ensure haproxy packages are present] ***********************************
changed: [servera.lab.example.com]TASK [haproxy : Ensure haproxy is started and enabled] *********************************
changed: [servera.lab.example.com]TASK [haproxy : Ensure haproxy configuration is set] ***********************************
changed: [servera.lab.example.com]RUNNING HANDLER [haproxy : reload haproxy] *********************************************
changed: [servera.lab.example.com]PLAY [Ensure Apache is deployed] *******************************************************TASK [Gathering Facts] *****************************************************************
ok: [serverc.lab.example.com]
ok: [serverb.lab.example.com]TASK [firewall : Ensure Firewall Sources Configuration] ********************************
ok: [serverb.lab.example.com] => (item={'zone': 'internal', 'service': 'http', 'source': '172.25.250.10'})
ok: [serverc.lab.example.com] => (item={'zone': 'internal', 'service': 'http', 'source': '172.25.250.10'})TASK [apache : Install http] ***********************************************************
changed: [serverb.lab.example.com]
changed: [serverc.lab.example.com]TASK [apache : Configure SELinux to allow httpd to connect to remote database] *********
ok: [serverb.lab.example.com]
ok: [serverc.lab.example.com]TASK [apache : http service state] *****************************************************
changed: [serverb.lab.example.com]
changed: [serverc.lab.example.com]PLAY [Ensure Web App is deployed] ******************************************************TASK [Gathering Facts] *****************************************************************
ok: [serverb.lab.example.com]
ok: [serverc.lab.example.com]TASK [webapp : Copy a stub file.] ******************************************************
ok: [serverb.lab.example.com]
ok: [serverc.lab.example.com]PLAY RECAP *****************************************************************************
servera.lab.example.com    : ok=6    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
serverb.lab.example.com    : ok=7    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
serverc.lab.example.com    : ok=7    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

访问测试,可以看到实现通过servera对serverb,serverc的轮询

[student@workstation inventory-variables (master *%)]$curl http://servera
This is serverb. (version v1.0)
[student@workstation inventory-variables (master *%)]$curl http://servera
This is serverc. (version v1.0)
[student@workstation inventory-variables (master *%)]$curl http://servera
This is serverb. (version v1.0)
[student@workstation inventory-variables (master *%)]$curl http://servera
This is serverc. (version v1.0)

因为需要对ansible-playbook的管理

git commit  -a -m "Use Group Vars"
git push

至此试验完成,执行以下命令清理环境

lab inventory-variables finish
cd .. && rm -rf inventory-variables
http://www.lryc.cn/news/92086.html

相关文章:

  • 毕业生高频常用材料线上签,高校毕业季契约锁电子签章一站式助力
  • .ini配置文件介绍与解析库使用
  • 牛客网Linux错题七
  • 牛课刷题Day5(编程题)
  • javascript基础二十五:说说你对函数式编程的理解?优缺点?
  • 常见JavaScript加密算法、JS加密算法
  • 题解2023.6.5
  • 与声音计算研究相关的挑战赛——DCASE和L3DAS
  • 实训总结-----Scrapy爬虫
  • 前端开发职业规划指南:如何做好职业规划与发展
  • 创业第一步:如何写好商业计划书
  • 【Linux驱动】字符设备驱动相关宏 / 函数介绍(module_init、register_chrdev)
  • axios解决跨域问题
  • R语言作图——热图聚类及其聚类结果输出
  • Tomcat优化
  • 我的GIT练习TWO
  • 个人器件库整理
  • javascript——内存管理
  • Qt5.15.2安卓Android项目开发环境配置
  • 第四十三章 弹跳训练2(灵识扫描)
  • 【location对象的方法,history对象,navigator--BOM】
  • 论文笔记:Normalizing Flows for Probabilistic Modeling and Inference
  • java 异常类介绍
  • shiro 550 反序列化rce
  • 【C++】---模板初阶(超详练气篇)
  • windows系统典型漏洞分析
  • WPF开发txt阅读器:需求分析和文件读写
  • C++服务器框架开发9——日志系统LogFormatter_4/各个类的关系梳理/std::function/std::get
  • arm平台上的MNN编译与运行
  • python 编译安装指定版本 for linux