ansible临时命令
使用所学的模块撰写ansible临时命令(adhoc模式)
一、部署web服务器
1、部署yum仓库
[student@ansible ansible]$ ansible node1 -m mount -a 'src=/dev/sr0 path=/mnt fstype=iso9660 state=mounted'
[student@ansible ansible]$ ansible node1 -m yum_repository -a 'file=centos name=AppStream description=AppStream baseurl=file:///mnt/AppStream enabled=yes gpgcheck=no'
[student@ansible ansible]$ ansible node1 -m yum_repository -a 'file=centos name=BaseOS description=BaseOS baseurl=file:///mnt/BaseOS enabled=yes gpgcheck=no
2、安装httpd
[student@ansible ansible]$ ansible node1 -m yum -a 'name=httpd state=installed'
[student@ansible ansible]$ ansible node1 -m service -a 'name=httpd state=started enabled=yes'
3、将/var/www/html目录做一个软链接,到/www
[student@ansible ansible]$ ansible node1 -m file -a 'src=/var/www/html dest=/www state=link'
4、在/www中新建index.html,内容为my name is chenyu(chenyu为你们自己名字的全拼)
[student@ansible ansible]$ ansible node1 -m copy -a 'dest=/www/index.html content="my name is liuxiang"'
5、实现在ansible中能够使用http://node1访问到该网页内容
[student@ansible ansible]$ ansible node1 -m firewalld -a 'service=http permanent=yes state=enabled'
[student@ansible ansible]$ ansible node1 -m sefcontext -a 'target=/www(/.*)? setype=httpd_sys_content_t state=present'
[student@ansible ansible]$ ansible node1 -m command -a 'restorecon -Rv /www'
[student@ansible ansible]$ ansible node1 -m service -a 'name=httpd state=restarted'
[student@ansible ansible]$ curl http://node1
my name is liuxiang
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?