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!
相关推荐
一个在高校打杂的6 分钟前
honeypot之opencanary(轻量化蜜罐)
linux·网络安全·网络攻击模型·安全威胁分析·策略模式
大明者省7 分钟前
Ubuntu22.04 宝塔面板与 XFCE 远程桌面端口兼容性分析
运维·服务器·数据库·笔记
s_w.h12 分钟前
【 linux 】认识make和makefile
linux·运维·bash
代码熬夜敲Q16 分钟前
Docker基础
运维·docker·容器
不怕犯错,就怕不做24 分钟前
ARM设备异常断电容易造成数据损坏,硬件如何设计
linux·驱动开发·嵌入式硬件
Harm灬小海28 分钟前
【云计算学习之路】学习Centos7系统-Linux软件包管理
linux·运维·服务器·学习·云计算·yum·rpm
1892280486130 分钟前
NY379固态MT29F32T08GSLBHL8-36QA:B
大数据·服务器·人工智能·科技·缓存
caicai_xiaobai31 分钟前
Ubuntu上Git安装步骤
linux·git·ubuntu
平行云41 分钟前
实时云渲染平台数据通道,支持3D应用文件上传下载分享无缝交互
linux·unity·云原生·ue5·gpu算力·实时云渲染·像素流送
淼淼爱喝水1 小时前
Ansible 变量管理实验
ansible·自动化运维