安装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这个页面可以自己写