ansible 批量部署安装apache

安装Apache并修改监听端口为8080

修改ServerName配置,执行apachectl -t命令不报错

设置默认主页hello world

启动服务并设开机自启

1)yum模块

[root@ansible ~]# ansible other -m yum -a 'name="lrzsz" state=removed'   
//lrzsz软件包名,removed=absent删除

[root@ansible ~]# ansible other -m yum -a 'name="lrzsz,lftp" state=installed'  
//安装多个软件包,不写state默认为安装

2)service模块

[root@ansible ~]# ansible other -m service -a 'name="sshd" enabled="yes"  state="started"' //sshd服务名,开机启动同时启动这个服务

3)setup模块
filter 过滤指定的关键字(可以过滤到我们需要的信息)

[root@ansible ~]# ansible cache -m setup -a 'filter=os'


[root@ansible ~]# ansible cache -m setup -a 'filter=ansible_distribution'

安装Apache

1)安装Apache服务设置开机自启

[root@ansible ~]# ansible cache -m yum -a 'name=httpd state=installed'

[root@ansible ~]# ansible cache -m service -a 'name=httpd enabled=yes state=started'

2)修改端口号为8080

[root@ansible ~]# ssh cache
Last login: Thu Sep  6 15:30:33 2018 from 192.168.1.51
[root@cache ~]# cat  /etc/httpd/conf/httpd.conf | grep Listen
Listen 80

[root@ansible ~]# ansible cache -m lineinfile -a 'path="/etc/httpd/conf/httpd.conf" regexp="^Listen " line="Listen 8080"'cache | SUCCESS => {
"backup": "", 
"changed": true, 
"msg": "line replaced"
}

[root@ansible ~]# ssh cache
Listen 8080

修改ServerName配置,执行apachectl -t命令不报错

[root@ansible ~]# ansible cache -m lineinfile -a 'path="/etc/httpd/conf/httpd.conf"  

[root@ansible ~]# ssh cache

[root@cache ~]# apachectl -t
Syntax OK

设置默认主页

[root@ansible ~]# ansible cache -m copy -a 'src=/root/index.html dest=/var/www/html/index.html'  
///root/index.html这个页面可以自己写
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值