additional course material RH294
Olaf Bohlen
2019-12-04 96eda8797a3510ea39108406fdbedd1d0a1d47e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
- name: Install a webserver and start the service
  hosts: server
  become: true
  remote_user: devops
  force_handlers: true
  vars:
    - installstate: present
  tasks:
    - name: Prepare Webserver
      block:
        - name: Install httpd
          package:
            name: httpd
            state: '{{ installstate }}'
        - name: create index.html
          copy:
            dest: /var/www/html/index.html
            content: 'Welcome to {{ ansible_fqdn }}!'
            mode: 0644
        - name: start httpd
          service:
            name: httpd
            state: started
            enabled: true
        - name: 'retrieve content from port 80'
          uri:
            url: "http://localhost:80/index.html"
            return_content: false
          ignore_errors: true
    - name: Change Webserver config to 8080
      block:
        - name: change listen port to 8080
          lineinfile:
            dest: /etc/httpd/conf/httpd.conf
            regexp: '^Listen 80$'
            line: 'Listen 8080'
            state: present
        - name: retrieve content from port 8080
          uri:
            url: "http://localhost:8080/index.html"
            return_content: false
      rescue:
        - name: restart webserver
          service:
            name: httpd
            state: restarted
      always:
        - name: retrieve content from port 8080
          uri:
            url: "http://localhost:8080/index.html"
            return_content: false