ansible的playbook练习题

ansible的playbook练习题

给受控主机分组

node1 属于 test01 主机组

node2 属于 test02 主机组

node3 和 node4 属于 web 主机组

node5 属于 test05 主机组

web 组属于 webtest 主机组

powershell 复制代码
[student@master ansible]$ vim inventory 
1、对node1主机操作,安装httpd服务,网页存放在/www目录中,能够通过curl http://node1访问到网页内容为welcome to luoqi(这里我给全部受控主机都做了,只对node1可以将hosts设为node1)
powershell 复制代码
[student@master ansible]$ vim httpd.yml
[student@master ansible]$ ansible-playbook httpd.yml
[student@master ansible]$ curl http://node1
welcome to luoqi[student@master ansible]$ 
2、对node2主机操作,创建一个1000MiB的分区,格式化成ext4的文件系统,并挂载到/testdir目录下,使用ansible node2 -m shell -a 'df -Th'验证
(1)添加一块硬盘(略)
powershell 复制代码
[student@master ansible]$ vim fenqu.yml
[student@master ansible]$ ansible-playbook fenqu.yml
[student@master ansible]$ ansible node2 -m shell -a 'df -Th'
node2 | CHANGED | rc=0 >>
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  4.0M     0  4.0M   0% /dev
tmpfs          tmpfs     985M     0  985M   0% /dev/shm
tmpfs          tmpfs     394M  5.6M  389M   2% /run
/dev/vda3      xfs        17G  1.2G   16G   8% /
/dev/vda1      xfs      1014M  182M  833M  18% /boot
tmpfs          tmpfs     197M     0  197M   0% /run/user/1000
/dev/vdb1      ext4      966M   24K  900M   1% /testdir
3、对node3主机操作创建卷组datastorage,逻辑卷database,大小为800M,格式化为xfs的文件系统,并挂载到/lv目录下,使用ansible node3 -m shell -a 'df -Th'验证

(1)添加一块硬盘(略)

powershell 复制代码
[student@master ansible]$ vim lv.yml
[student@master ansible]$ ansible-playbook lv.yml
[student@master ansible]$ ansible node3 -m shell -a 'df -Th'
node3 | CHANGED | rc=0 >>
Filesystem                      Type      Size  Used Avail Use% Mounted on
devtmpfs                        devtmpfs  4.0M     0  4.0M   0% /dev
tmpfs                           tmpfs     985M     0  985M   0% /dev/shm
tmpfs                           tmpfs     394M  5.6M  389M   2% /run
/dev/vda3                       xfs        17G  1.3G   16G   8% /
/dev/vda1                       xfs      1014M  182M  833M  18% /boot
tmpfs                           tmpfs     197M     0  197M   0% /run/user/0
tmpfs                           tmpfs     197M     0  197M   0% /run/user/1000
/dev/mapper/datasorage-database xfs       794M   38M  757M   5% /lv
4、创建名为/home/student/ansible/tools.yml 的 playbook,能够实现以下目的:

(1)将 php 和 tftp 软件包安装到 test01、test02 和 web 主机组中的主机上

(2)将 RPM Development Tools 软件包组安装到 test01 主机组中的主机上

(3)将 test01 主机组中的主机上所有软件包升级到最新版本

powershell 复制代码
[student@master ansible]$ vim tools.yml
[student@master ansible]$ ansible-playbook tools.yml
5、编写剧本/home/student/ansible/jihua.yml
(1)在 test02 组中的被管理主机运行
( 2)为用户 student 创建计划任务: student 用户每隔 5 分钟执行 echo "hello tarena"
powershell 复制代码
[student@master ansible]$ vim jihua.yml
[student@master ansible]$ ansible-playbook jihua.yml

PLAY [cron] ****************************************************************************

TASK [Gathering Facts] *****************************************************************
ok: [node2]

TASK [cron1] ***************************************************************************
changed: [node2]

PLAY RECAP *****************************************************************************
node2                      : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[student@master ansible]$ ansible node2 -m shell -a 'crontab -l -u student'
node2 | CHANGED | rc=0 >>
#Ansible: cron one
*/5 * * * * echo hello tarena
6、创建剧本/home/student/ansible/webdev.yml,满足下列要求:

(1)在 test01 主机组运行

(2)创建目录/webdev,属于 webdev 组,权限为 rwxrwxr-x,具有 SetGID 特殊权限

(3)使用符号链接/var/www/html/webdev 链接到/webdev 目录

(4)创建文件/webdev/index.html,内容是 It's works!

(5)查看 test01 主机组的 web 页面 http://node1/webdev/将显示 It's works!

powershell 复制代码
[student@master ansible]$ vim webdev.yml
[student@master ansible]$ ansible-playbook webdev.yml
[student@master ansible]$ curl http://node1/webdev/
It's works!
相关推荐
大耳朵-小飞象1 小时前
电力安全运维的智能密码:BACS如何破解设备全生命周期管理难题,让电网安全“看得见、管得住”?
运维·安全·智慧城市·能耗系统·楼宇智控·未来生活
极客侃科技1 小时前
制造企业 MES/APS 选型:SAP PP/DS 集成、ERP-MES 边界划分与一体化架构要点
运维·架构·制造
HLC++2 小时前
Linux的进程间通信
android·linux·服务器
华清远见IT开放实验室3 小时前
实验室建设案例 | 石家庄科技信息职业学院嵌入式实验室——从底层硬件到系统应用,一所应用型高校的嵌入式人才培养这样落地
linux·arm开发·stm32·嵌入式硬件·高校·实验室建设
白露与泡影3 小时前
Arthas 实战指南:从方法耗时定位到 JVM 变量热修改
服务器·jvm·c#
神奇霸王龙4 小时前
Claude Code屠榜:MiMo与Grok紧追Codex
服务器·网络·人工智能·gpt·ai·ai编程
Web极客码4 小时前
WordPress SEO优化:提升网站排名的13个关键步骤
服务器·seo·wordpress
生活爱好者!5 小时前
我把NAS当作下载机,docker一键部署qb
运维·docker·容器
groundhappy6 小时前
idalib安装和codex ida-mcp配置
linux·开发语言·python
尽兴-6 小时前
企业业务系统架构选型与渐进式演进
运维·系统架构·devops