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!
相关推荐
EasyGBS8 小时前
摄像头还在线,画面已经不能用了?国标GB28181视频平台EasyGBS视频质量诊断怎么用
服务器·安全·音视频
程序员-Benothing8 小时前
Vim编辑器从入门到精通:模式、快捷键、配置、插件
linux·运维·服务器
m0_646429979 小时前
Docker 完整核心知识点总结(超通俗易懂版)
运维·docker·容器
wdfk_prog9 小时前
LWIP教程 09:从 `tcp_slowtmr()` 到 Fast Retransmit——TCP 超时重传与重复 ACK
服务器·网络·数据库·网络协议·tcp/ip
‎ദ്ദിᵔ.˛.ᵔ₎9 小时前
linux 进程信号 (上)
linux·服务器
亚川楼宇自控系统数据中心厂家9 小时前
IBMS 集成管理系统:如何打通楼宇自控实现建筑一体化管控
运维
15Moonlight9 小时前
Linux网络(02):Socket 编程 UDP
linux·网络·udp
迪康Defender9 小时前
终端安全审批体系设计:如何平衡安全管控与业务连续性
运维·服务器·安全·运维开发·学习方法·业界资讯·远程工作