Ansible Kurs


Inhalt


Willkommen

Einstieg

Struktur & Rollen

Templates

Arbeiten mit Containern

Erweiterte Übung

Aufgabe: Ausrollen Webserver

Conditionals

Ansible-Vault

Dark Mode

Aufgabe: Ausrollen Webserver

  1. Apache2/Nginx installieren
  2. Konfiguration erstellen
  3. Trigger zum neu starten des httpd
root@mia-ansible-01:~/ansible/roles# tree training.configure-httpd/
training.configure-httpd/
├── files
│   ├── config
│   │   ├── apache2.conf
│   │   ├── envvars
│   │   ├── mods-available
│   │   │   ├── access_compat.load
│   │   │   ├── actions.conf
│   │   │   ├── actions.load
│	│	│		...
│   │   ├── mods-enabled
│   │   │   ├── access_compat.load -> ../mods-available/access_compat.load
│   │   │   ├── alias.conf -> ../mods-available/alias.conf
│   │   │   ├── alias.load -> ../mods-available/alias.load
│	│	│		...
│   │   ├── ports.conf
│   │   ├── sites-available
│   │   │   ├── 000-default.conf
│   │   │   └── default-ssl.conf
│   │   └── sites-enabled
│   │       └── 000-default.conf
│   └── content
│       ├── index.html
│       └── stylesheet.css
├── handlers
│   └── main.yml
└── tasks
    └── main.yml
# tasks/main.yml

- name: Install apache2
  ansible.builtin.apt:
    name: apache2
    state: present

- name: Copy apache2 configuration
  ansible.builtin.copy:
    src: config/
    dest: /etc/apache2/
    owner: root
    group: root
  notify:
    - Restart apache2

- name: Copy web content
  ansible.builtin.copy:
    src: content/
    dest: /var/www/html
    owner: root
    group: root
# handlers/main.yml

- name: Restart apache2
  ansible.builtin.systemd_service:
    state: restarted
    name: apache2