题1
创建playbook
[root@use01 playbook]# cat httpd.yml
---
- hosts: web
remote_user: root
tasks:
- name: install
yum: name=httpd
- name: config
copy: src=/playbook/httpd.conf dest=/etc/httpd/conf/
notify: restart httpd
- name: service
service: name=httpd state=started enabled=yes
handlers:
- name: restart httpd
service: name=httpd state=restarted
执行
[root@use01 playbook]# ansible-playbook httpd.yml
题2
在httpd上创建两个基于主机名的虚拟主机,并指定日志路径
[root@use02 ~]# cat /etc/httpd/conf.d/test.conf
<VirtualHost *:80>
ServerName www.X.com
DocumentRoot "/data/xsite"
<Directory "/data/xsite">
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
ErrorLog "/var/log/httpd/x.err"
CustomLog "/var/log/httpd/x.access" combined
</VirtualHost>
<VirtualHost *:80>
ServerName www.Y.com
DocumentRoot "/data/ysite"
<Directory "/data/ysite">
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
ErrorLog "/var/log/httpd/y.err"
CustomLog "/var/log/httpd/y.access" combined
</VirtualHost>