ansible临时命令

使用所学的模块撰写ansible临时命令(ad­hoc模式)

一、部署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
posted @ 2022-10-24 22:45  Archer-x  阅读(44)  评论(0编辑  收藏  举报