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:44] – [Ausführen von Ansible Playbooks] 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 715: | Line 726: | ||
==== 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. <wrap em>Um das Playbook vom oberen Beispiel auszuführen, | + | 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 746: | 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 764: | Line 814: | ||
* https:// | * https:// | ||
* https:// | * https:// | ||
+ | * https:// | ||
---- | ---- | ||
Line 795: | Line 846: | ||
* [[http:// | * [[http:// | ||
- | |||
- | |||
- | |||
- | ===== Eigene Module erstellen ===== | ||
---- | ---- | ||
- | |||
- | |||
- | |||
- | |||
===== Weiteres ===== | ===== Weiteres ===== |