commit | author | age
|
97d9af
|
1 |
--- |
SU |
2 |
- name: Install a webserver and start the service |
|
3 |
hosts: server |
|
4 |
become: true |
|
5 |
remote_user: devops |
|
6 |
force_handlers: true |
|
7 |
vars: |
|
8 |
- installstate: present |
|
9 |
tasks: |
|
10 |
- name: Install httpd |
|
11 |
package: |
|
12 |
name: httpd |
|
13 |
state: '{{ installstate }}' |
|
14 |
- name: create index.html |
|
15 |
copy: |
|
16 |
dest: /var/www/html/index.html |
|
17 |
content: 'Welcome to {{ ansible_fqdn }}!' |
|
18 |
mode: 0644 |
|
19 |
- name: start httpd |
|
20 |
service: |
|
21 |
name: httpd |
|
22 |
state: started |
|
23 |
enabled: true |
|
24 |
- name: 'retrieve content from port 80' |
|
25 |
uri: |
|
26 |
url: "http://localhost:80/index.html" |
|
27 |
return_content: false |
|
28 |
ignore_errors: true |
|
29 |
- name: change listen port to 8080 |
|
30 |
lineinfile: |
|
31 |
dest: /etc/httpd/conf/httpd.conf |
|
32 |
regexp: '^Listen 80$' |
|
33 |
line: 'Listen 8080' |
|
34 |
state: present |
|
35 |
notify: |
|
36 |
- restart httpd |
|
37 |
- name: retrieve content from port 8080 |
|
38 |
uri: |
|
39 |
url: "http://localhost:8080/index.html" |
|
40 |
return_content: false |
|
41 |
|
|
42 |
|
|
43 |
handlers: |
|
44 |
- name: restart httpd |
|
45 |
service: |
|
46 |
name: httpd |
|
47 |
state: restarted |
|
48 |
|
|
49 |
- name: verify |
|
50 |
hosts: server |
|
51 |
tasks: |
|
52 |
- name: retrieve content from port 80 |
|
53 |
uri: |
|
54 |
url: "http://localhost:80/index.html" |
|
55 |
return_content: false |
|
56 |
ignore_errors: true |
|
57 |
- name: retrieve content from port 8080 |
|
58 |
uri: |
|
59 |
url: "http://localhost:8080/index.html" |
|
60 |
return_content: false |