官术网_书友最值得收藏!

Installing and configuring a web server

Now that we have made some generic changes to the operating system, let's move on to actually creating a web server. We are splitting those two phases so that we can share the first phase between every machine and apply the second only to web servers.

For this second phase, we will create a new playbook called webserver.yaml with the following content:

--- 
- hosts: all
remote_user: ansible
tasks:
- name: Ensure the HTTPd package is installed
yum:
name: httpd
state: present
become: True
- name: Ensure the HTTPd service is enabled and running
service:
name: httpd
state: started
enabled: True
become: True
- name: Ensure HTTP can pass the firewall
firewalld:
service: http
state: enabled
permanent: True
immediate: True
become: True
- name: Ensure HTTPS can pass the firewall
firewalld:
service: https
state: enabled
permanent: True
immediate: True
become: True

As you can see, the first two tasks are the same as the ones in the example at the beginning of this chapter, and the last two tasks are used to instruct FirewallD to let the HTTP and HTTPS traffic pass.

Let's run this script with the following:

$ ansible-playbook -i test01.fale.io, webserver.yaml  

This results in the following:

PLAY [all] *************************************************

TASK [Gathering Facts] *************************************
ok: [test01.fale.io]

TASK [Ensure the HTTPd package is installed] ***************
ok: [test01.fale.io]

TASK [Ensure the HTTPd service is enabled and running] *****
ok: [test01.fale.io]

TASK [Ensure HTTP can pass the firewall] *******************
changed: [test01.fale.io]

TASK [Ensure HTTPS can pass the firewall] ******************
changed: [test01.fale.io]

PLAY RECAP *************************************************
test01.fale.io : ok=5 changed=2 unreachable=0 failed=0

Now that we have a web server, let's publish a small, single-page, static website.

主站蜘蛛池模板: 景德镇市| 昆山市| 即墨市| 新丰县| 宜丰县| 新野县| 抚州市| 综艺| 嘉峪关市| 五指山市| 蕲春县| 昌邑市| 堆龙德庆县| 江津市| 稷山县| 永善县| 慈溪市| 于田县| 遂川县| 延安市| 呼和浩特市| 梓潼县| 贡山| 天门市| 饶阳县| 肥城市| 申扎县| 铅山县| 崇左市| 和静县| 安宁市| 山阳县| 巴林左旗| 万宁市| 南平市| 许昌市| 简阳市| 云龙县| 浪卡子县| 库车县| 房产|