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!
相关推荐
阿尔法哲7 小时前
CentOS系统 OPENSSH一键升级脚本
linux·centos
做运维的阿瑞2 天前
一张脑图吃透Linux用户权限:useradd、usermod、umask、setfacl、chmod特殊位、chown、chage连招大全
linux
handsome123453 天前
CentOS 8.5.2.111部署Zabbix6.0 手把手、保姆级
运维·mysql·centos·zabbix·监控·centos8·zabbix6·linux源
dessler3 天前
Hadoop HDFS-读写流程
linux·运维·hdfs
FIT2CLOUD飞致云4 天前
操作教程|使用Cursor工具连接JumpServer资产
运维·开源
会飞的小蛮猪4 天前
Jenkins运维之路(Slave容器节点)
运维·ci/cd·jenkins
做运维的阿瑞4 天前
15 分钟图解 Linux 内核到发行版:运维选型不再纠结
linux
刘立军4 天前
内网的服务如何能在公网使用?
运维
飞询4 天前
docker 部署 sftp
运维·docker
LH_R5 天前
OneTerm开源堡垒机实战(四):访问授权与安全管控
运维·后端·安全