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!
相关推荐
甲鱼9298 小时前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维
Johny_Zhao1 天前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
YuMiao1 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
chlk1232 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑2 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件2 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒2 天前
OpenClaw 多 Agent 配置实战指南
运维
深紫色的三北六号3 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash3 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI3 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github