Variablen für ssh-management
This commit is contained in:
parent
db6f5ac31a
commit
a295c3f704
3 changed files with 110 additions and 0 deletions
93
README.md
Normal file
93
README.md
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
# Ansible Workshop
|
||||||
|
|
||||||
|
## Vorbereitung
|
||||||
|
|
||||||
|
Check dieses Repostitory mit git aus und wechsel in das Verzeichnis
|
||||||
|
|
||||||
|
```
|
||||||
|
git remote add origin https://git.serverwg.de/fager/ansible-workshop.git
|
||||||
|
cd ansible-workshop
|
||||||
|
```
|
||||||
|
|
||||||
|
Kopiere das Beispielinventar:
|
||||||
|
|
||||||
|
```
|
||||||
|
cp -r inventory/demo inventory/myinv
|
||||||
|
```
|
||||||
|
|
||||||
|
Kopiere die Beispiel ansible.cfg:
|
||||||
|
|
||||||
|
```
|
||||||
|
cp ansible.cfg.dist ansible.cfg
|
||||||
|
```
|
||||||
|
|
||||||
|
Passe die Konfiguration an Dein Inventar an:
|
||||||
|
|
||||||
|
```
|
||||||
|
[defaults]
|
||||||
|
inventroy = ./inventory/myinv
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Für die Demos werden 3 VMs benötigt. Diese müssen bereits existieren und
|
||||||
|
sind nicht Bestandteil des Workshops.
|
||||||
|
|
||||||
|
Im Beispiel-Inventar sind drei Server vorgesehen:
|
||||||
|
|
||||||
|
- server1.example.com
|
||||||
|
- server2.example.com
|
||||||
|
- server3.example.com
|
||||||
|
|
||||||
|
Die Servernamen werden an verschiedenen Stellen im Inventar verwendet und
|
||||||
|
referenziert.
|
||||||
|
|
||||||
|
Es ist daher empfehlenswert, die Servernamen zuerst so zu belassen und im
|
||||||
|
Inventar die IP der Systeme anzupassen.
|
||||||
|
|
||||||
|
Dafür öffnest Du die Dateien `inventory/myinv/host_vars/server[1-3].example.com.yml`
|
||||||
|
und passt die Host-Konfiguration an die IP Deiner VMs an:
|
||||||
|
|
||||||
|
```
|
||||||
|
---
|
||||||
|
ansible_host = 192.0.2.10
|
||||||
|
```
|
||||||
|
|
||||||
|
## Funktionstest des Inventars
|
||||||
|
|
||||||
|
Alle Befehle in diesem Workshop beziehen sich auf das Verzeichnis `ansible-workshop`.
|
||||||
|
|
||||||
|
Die Ansible-Befehle suchen im aktuellen Verzeichnis nach einer `ansible.cfg` und
|
||||||
|
verwenden diese dann als Ihre Konfiguration.
|
||||||
|
|
||||||
|
Ob das Inventar sauber eingelesen wird, lässt sich durch `ansible-inventory` testen.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ansible-inventory --graph
|
||||||
|
@all:
|
||||||
|
|--@ungrouped:
|
||||||
|
|--@loadbalancer:
|
||||||
|
| |--server1.example.com
|
||||||
|
|--@webserver:
|
||||||
|
| |--server2.example.com
|
||||||
|
| |--server3.example.com
|
||||||
|
```
|
||||||
|
|
||||||
|
Ebenso können zum Testen einmal alle Variablen für einen Host abgefragt werden.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ ansible-inventory --host server1.example.com
|
||||||
|
{
|
||||||
|
"ansible_host": "192.0.2.10",
|
||||||
|
"automation_keys": [
|
||||||
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMj6DlLhdnhknWeC4Zz48P7pzTH6JNFUTcOaxm/8V9fa fager@t530fedo"
|
||||||
|
],
|
||||||
|
"automation_user": "ansible"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Einrichten des ssh-keys für die Automatisierung
|
||||||
|
|
||||||
|
TBD
|
||||||
|
|
||||||
|
## Das Playbooks Verzeichnis
|
||||||
|
|
||||||
9
inventory/demo/group_vars/all.yml
Normal file
9
inventory/demo/group_vars/all.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
|
||||||
|
# Die Automatisierung soll mit dem User "ansible" erfolgen
|
||||||
|
automation_user: ansible
|
||||||
|
|
||||||
|
# Für die Anmeldung wird ein oder mehrere Keys hinterlegt
|
||||||
|
automation_keys:
|
||||||
|
- "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMj6DlLhdnhknWeC4Zz48P7pzTH6JNFUTcOaxm/8V9fa fager@t530fedo"
|
||||||
|
|
||||||
8
playbooks/ping.yml
Normal file
8
playbooks/ping.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
- name: Ping all hosts
|
||||||
|
hosts: all
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Ping
|
||||||
|
ansible.builtin.ping: {}
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue