Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
redhat:other-redhat:ansible:start [2017/07/18 16:08] – [Schritt 5 - Abfüllen der db Rolle] michael | redhat:other-redhat:ansible:start [2020/05/13 15:01] (current) – [Next, we have a set of tasks:] michael | ||
---|---|---|---|
Line 18: | Line 18: | ||
<WRAP left round info 100%> | <WRAP left round info 100%> | ||
**Weitere nützliche Informationen: | **Weitere nützliche Informationen: | ||
- | * [[https:// | + | * **'' |
</ | </ | ||
+ | ---- | ||
+ | |||
+ | ====== Erste Schritte mit Ansible ====== | ||
+ | |||
+ | <WRAP center box 100%> | ||
===== Installation auf CentOS / RHEL7 ===== | ===== Installation auf CentOS / RHEL7 ===== | ||
Installiert, | Installiert, | ||
Line 28: | Line 33: | ||
# yum install ansible | # yum install ansible | ||
</ | </ | ||
+ | </ | ||
- | ---- | ||
- | ====== Erste Schritte mit Ansible ====== | + | In den ersten Schritten, wird Ansible grundlegend Konfiguriert und erste Test-Kommandos abgesetzt! |
- | In den ersten Schritten, wird Ansible grundlegend Konfiguriert und erste Test-Kommandos abgesetzt! <wrap em> | + | |
+ | <wrap em> | ||
'' | '' | ||
Line 111: | Line 117: | ||
Falls überprüft werden soll, ob man auf den geplanten Zielsystemen auch wirklich root-Zugriffe hat; kann man dies mit folgendem Befehl überprüfen: | Falls überprüft werden soll, ob man auf den geplanten Zielsystemen auch wirklich root-Zugriffe hat; kann man dies mit folgendem Befehl überprüfen: | ||
- | <sxh bash; gutter: false; highlight: [1]> | + | <WRAP center box 100%> |
+ | <code> | ||
[rebermi@vstif2 ~]$ ansible all -s -m shell -a id | [rebermi@vstif2 ~]$ ansible all -s -m shell -a id | ||
+ | </ | ||
+ | <sxh bash; gutter: false;> | ||
vstif1.pnet.ch | SUCCESS | rc=0 >> | vstif1.pnet.ch | SUCCESS | rc=0 >> | ||
uid=0(root) gid=0(root) groups=0(root) | uid=0(root) gid=0(root) groups=0(root) | ||
</ | </ | ||
+ | </ | ||
+ | |||
===== Der Aufbau von einfachen Playbooks ===== | ===== Der Aufbau von einfachen Playbooks ===== | ||
Line 283: | Line 294: | ||
</ | </ | ||
- | This module allows us to specify a package and the state that it should be in, which is " | + | This module allows us to specify a package and the state that it should be in, which is " |
The " | The " | ||
Line 324: | Line 335: | ||
Für unser Beispiel, werden wir in einem separaten Ordner unsere Variablen definieren, drei unterschiedliche Rollen erstellen und Konfigurationstemplates zu einzelnen Pakete vordefinieren. Unsere fertige Struktur, sollte nach unserer Arbeit in etwa so aussehen: | Für unser Beispiel, werden wir in einem separaten Ordner unsere Variablen definieren, drei unterschiedliche Rollen erstellen und Konfigurationstemplates zu einzelnen Pakete vordefinieren. Unsere fertige Struktur, sollte nach unserer Arbeit in etwa so aussehen: | ||
- | <sxh bash> | + | <sxh bash; gutter: false;> |
. | . | ||
├── deploy-lamp.yml | ├── deploy-lamp.yml | ||
Line 415: | Line 426: | ||
//Dieses Kommando legt uns nun folgende Ordnungsstruktur an:// | //Dieses Kommando legt uns nun folgende Ordnungsstruktur an:// | ||
- | <sxh bash> | + | <sxh bash; gutter: false;> |
roles/ | roles/ | ||
├── common | ├── common | ||
Line 461: | Line 472: | ||
template: src=ntp.conf.j2 dest=/ | template: src=ntp.conf.j2 dest=/ | ||
tags: ntp | tags: ntp | ||
- | notify: restart ntp #(If configuration is changed by ansible, notify will contact the Handler=" | + | notify: restart ntp #(If configuration is changed by ansible, |
# This task starts and enables the ntp deamon | # This task starts and enables the ntp deamon | ||
Line 635: | Line 646: | ||
</ | </ | ||
==== Schritt 6 - Abfüllen der web Rolle ==== | ==== Schritt 6 - Abfüllen der web Rolle ==== | ||
+ | In der web-Rolle konfigurieren wir unseren Apache 2.4 Webserver. Dieser wird hingegen zum db-Server, nur auf jenen Servern installiert, | ||
+ | |||
+ | __Beginnen wir wieder mit der Hauptdatei im tasks Ordner:__ | ||
+ | |||
+ | < | ||
+ | # vim roles/ | ||
+ | </ | ||
+ | |||
+ | <sxh bash> | ||
+ | --- | ||
+ | # Hier wird der Webserver & PHP Installiert | ||
+ | - name: Install httpd and php | ||
+ | yum: name={{ item }} state=present | ||
+ | with_items: | ||
+ | - httpd | ||
+ | - php | ||
+ | - php-mysql | ||
+ | |||
+ | - name: Install web role specific dependencies | ||
+ | yum: name={{ item }} state=installed | ||
+ | with_items: | ||
+ | - git | ||
+ | |||
+ | - name: Start firewalld | ||
+ | service: name=firewalld state=started enabled=yes | ||
+ | |||
+ | - name: insert firewalld rule for httpd | ||
+ | firewalld: port={{ httpd_port }}/tcp permanent=true state=enabled immediate=yes | ||
+ | |||
+ | - name: http service state | ||
+ | service: name=httpd state=started enabled=yes | ||
+ | |||
+ | - name: Configure SELinux to allow httpd to connect to remote database | ||
+ | seboolean: name=httpd_can_network_connect_db state=true persistent=yes | ||
+ | |||
+ | |||
+ | |||
+ | # Falls gewünst, kann mit folgenden zwei Zeilen auch ein CMS von einem GitHub Repository heruntergeladen und in das Webverzeichniss verschoben werden. | ||
+ | #- name: Copy the code from repository | ||
+ | # git: repo={{ repository }} dest=/ | ||
+ | |||
+ | # Hier wird die Test index.php erstellt: | ||
+ | - name: Creates the index.php file | ||
+ | template: src=index.php.j2 dest=/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | __Zum Schluss erstellen wir noch das Template für unsere index.php: | ||
+ | |||
+ | < | ||
+ | # vim roles/ | ||
+ | </ | ||
+ | |||
+ | <sxh php> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | < | ||
+ | </ | ||
+ | <a href=http:// | ||
+ | </ | ||
+ | <? | ||
+ | Print " | ||
+ | echo exec(' | ||
+ | | ||
+ | echo "List of Databases: </ | ||
+ | {% for host in groups[' | ||
+ | $link = mysqli_connect(' | ||
+ | {% endfor %} | ||
+ | $res = mysqli_query($link, | ||
+ | while ($row = mysqli_fetch_assoc($res)) { | ||
+ | echo $row[' | ||
+ | } | ||
+ | ?> | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
==== Schritt 7 - Erstellen der zentralen Variablensammlung ==== | ==== Schritt 7 - Erstellen der zentralen Variablensammlung ==== | ||
+ | Zum Abschluss unseres selbst-erstellten Playbooks, müssen wir nun natürlich noch sämtliche (In den Rollen und Konfigurationen verwendeten) Variablen definieren und zuweisen. Dies machen wir in dem Verzeichnis group_vars. | ||
+ | __Da dieses noch nicht existiert erstellen wir dies zuerst:__ | ||
+ | < | ||
+ | # mkdir group_vars | ||
+ | </ | ||
+ | <WRAP center round tip 100%> | ||
+ | ''< | ||
+ | </ | ||
+ | |||
+ | __Erstellen der Variablensammlung für alle Hosts:__ | ||
+ | < | ||
+ | # vim group_vars/ | ||
+ | </ | ||
+ | |||
+ | <sxh bash> | ||
+ | # Variables listed here are applicable to all host groups | ||
+ | httpd_port: 80 | ||
+ | ntpserver: ch.pool.ntp.org | ||
+ | repository: https:// | ||
+ | </ | ||
+ | |||
+ | __Erstellen der Variablenzusammenstellung für den DB-Server: | ||
+ | < | ||
+ | # vim group_vars/ | ||
+ | </ | ||
+ | |||
+ | <sxh bash> | ||
+ | # Variabenl für die dbservers Gruppe | ||
+ | |||
+ | mysqlservice: | ||
+ | mysql_port: 3306 | ||
+ | dbuser: michael | ||
+ | dbname: application-server-db1 | ||
+ | upassword: abc123!M | ||
+ | |||
+ | mysql_root_password: | ||
+ | </ | ||
+ | |||
+ | <wrap em> | ||
---- | ---- | ||
===== Ausführen von Ansible Playbooks ===== | ===== Ausführen von Ansible Playbooks ===== | ||
+ | Ansible Playbooks, können einfach so gestartet werden, oder auch mit der Angabe einer mitgelieferten hosts datei. ''< | ||
==== Variante 1 - Playbook ohne hosts Angabe ausführen ==== | ==== Variante 1 - Playbook ohne hosts Angabe ausführen ==== | ||
In dieser Variante, gellten alle vordefinierten Gruppen und zuordnungen unter ''/ | In dieser Variante, gellten alle vordefinierten Gruppen und zuordnungen unter ''/ | ||
Line 668: | Line 796: | ||
<WRAP center round download 100%> | <WRAP center round download 100%> | ||
==== Fertige Playbooks zum Download ==== | ==== Fertige Playbooks zum Download ==== | ||
- | Unter dem unten aufgeführten Link, werden von Ansible unteranderem bereits fertige Playbooks, zu folgenden Themen zum Download angeboten: -> '' | + | '' |
* '' | * '' | ||
Line 686: | Line 814: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
---- | ---- | ||
Line 717: | Line 846: | ||
* [[http:// | * [[http:// | ||
- | |||
- | |||
- | |||
- | ===== Eigene Module erstellen ===== | ||
---- | ---- | ||
- | |||
- | |||
- | |||
- | |||
===== Weiteres ===== | ===== Weiteres ===== |