tachtler:benutzer_mit_ansible_verwalten
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
tachtler:benutzer_mit_ansible_verwalten [2020/03/20 06:02] – [~/ansible/00_user_add.yml] klaus | tachtler:benutzer_mit_ansible_verwalten [2020/03/20 13:01] (aktuell) – [/home/ansible/ansible/00_user.yml] klaus | ||
---|---|---|---|
Zeile 25: | Zeile 25: | ||
===== Aufgaben ===== | ===== Aufgaben ===== | ||
- | Aufbauend auf die Installation und Einrichtung von [[https:// | + | Aufbauend auf die Installation und Einrichtung von [[https:// |
- die Erstellung von Benutzern, auf dem [[https:// | - die Erstellung von Benutzern, auf dem [[https:// | ||
+ | - die Modifizierung von Benutzern, auf dem [[https:// | ||
- auf dem [[https:// | - auf dem [[https:// | ||
- die auf dem [[https:// | - die auf dem [[https:// | ||
- Mitglieder der Gruppe '' | - Mitglieder der Gruppe '' | ||
- | + | | |
- | Aufbauend auf die Installation und Einrichtung von [[https:// | + | |
- | | + | |
- | + | ||
- | Aufbauend auf die Installation und Einrichtung von [[https:// | + | |
- | - die Löschung von Benutzern auf **__allen__ Servern**, auf dem [[https:// | + | |
===== Konfiguration ===== | ===== Konfiguration ===== | ||
Zeile 144: | Zeile 140: | ||
:!: **HINWEIS** - **Eine Beschreibung zur " | :!: **HINWEIS** - **Eine Beschreibung zur " | ||
- | * [[tachtler:benutzer_mit_ansible_einrichten# | + | * [[tachtler:benutzer_mit_ansible_verwalten# |
Die Konfigurationsdatei '' | Die Konfigurationsdatei '' | ||
Zeile 259: | Zeile 255: | ||
Eigenschaft: | Eigenschaft: | ||
- | ===== ~/ | + | ==== ~/ |
Die Konfigurationsdatei '' | Die Konfigurationsdatei '' | ||
Zeile 274: | Zeile 270: | ||
- hosts: all | - hosts: all | ||
vars_files: | vars_files: | ||
- | - / | + | - inventories/ |
roles: | roles: | ||
- { role: 00_user } | - { role: 00_user } | ||
Zeile 299: | Zeile 295: | ||
Die Definition, das das **Playbook** nachfolgende Variablen Datei verwenden soll. | Die Definition, das das **Playbook** nachfolgende Variablen Datei verwenden soll. | ||
- | * <code yaml> | + | * <code yaml> |
Die Definition, der Variablen Datei welche das **Playbook** verwenden soll. | Die Definition, der Variablen Datei welche das **Playbook** verwenden soll. | ||
Zeile 311: | Zeile 307: | ||
Welche **role** (Rolle) das **Playbook** benutzen soll. | Welche **role** (Rolle) das **Playbook** benutzen soll. | ||
- | ==== ~/ | + | ==== ~/ |
- | Die Verzeichnisstruktur für die **role** (Rolle) - '' | + | Die Verzeichnisstruktur für die **role** (Rolle) - '' |
< | < | ||
- | $ mkdir -p ~/ | + | $ mkdir -p ~/ |
</ | </ | ||
- | Die Konfigurationsdatei '' | + | Die Konfigurationsdatei '' |
< | < | ||
- | $ touch ~/ | + | $ touch ~/ |
</ | </ | ||
- | Der Inhalt der Konfigurationsdatei '' | + | Der Inhalt der Konfigurationsdatei '' |
<code yaml> | <code yaml> | ||
- | --- ### Add users, groups and creates | + | --- ### Add, modifies and delete |
# | # | ||
- | # # ansible-playbook -i / | + | # # ansible-playbook -i / |
# | # | ||
- name: Make sure group ' | - name: Make sure group ' | ||
Zeile 341: | Zeile 337: | ||
owner: root | owner: root | ||
validate: visudo -cf %s | validate: visudo -cf %s | ||
- | - name: Ensure group exists. | + | - name: Ensure user NOT exists, if NOT active. |
+ | user: | ||
+ | name: "{{ item.value.name }}" | ||
+ | remove: yes | ||
+ | state: absent | ||
+ | when: " | ||
+ | with_dict: | ||
+ | - "{{ users }}" | ||
+ | no_log: True | ||
+ | - name: Ensure group NOT exists, if NOT active. | ||
+ | group: | ||
+ | name: "{{ item.value.group }}" | ||
+ | state: absent | ||
+ | when: " | ||
+ | with_dict: | ||
+ | - "{{ users }}" | ||
+ | no_log: True | ||
+ | - name: Ensure group exists, ONLY if active. | ||
group: | group: | ||
gid: "{{ item.value.gid }}" | gid: "{{ item.value.gid }}" | ||
name: "{{ item.value.group }}" | name: "{{ item.value.group }}" | ||
state: present | state: present | ||
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
no_log: True | no_log: True | ||
- | - name: Ansible-Host - Ensure user exists. | + | - name: Ansible-Host - Ensure user exists, ONLY if active. |
user: | user: | ||
append: yes | append: yes | ||
Zeile 365: | Zeile 379: | ||
state: present | state: present | ||
uid: "{{ item.value.uid }}" | uid: "{{ item.value.uid }}" | ||
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
delegate_to: | delegate_to: | ||
no_log: True | no_log: True | ||
- | - name: Clients - Ensure user exists. | + | - name: Clients - Ensure user exists, ONLY if active. |
user: | user: | ||
append: yes | append: yes | ||
Zeile 380: | Zeile 395: | ||
state: present | state: present | ||
uid: "{{ item.value.uid }}" | uid: "{{ item.value.uid }}" | ||
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
no_log: True | no_log: True | ||
- | - name: Set exclusive authorized key for users taken from file. | + | - name: Set exclusive authorized key for users taken from file, ONLY if active. |
authorized_key: | authorized_key: | ||
user: "{{ item.value.name }}" | user: "{{ item.value.name }}" | ||
Zeile 389: | Zeile 405: | ||
state: present | state: present | ||
exclusive: True | exclusive: True | ||
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
no_log: True | no_log: True | ||
- | - name: Add users to group ' | + | - name: Add users to group ' |
user: | user: | ||
append: yes | append: yes | ||
groups: wheel | groups: wheel | ||
name: "{{ item.value.name }}" | name: "{{ item.value.name }}" | ||
- | when: " | + | when: |
+ | - " | ||
+ | - " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
- | no_log: True | + | no_log: True |
+ | - name: Remove users from all groups except the primary group, if set to False. | ||
+ | user: | ||
+ | append: no | ||
+ | groups: '' | ||
+ | name: "{{ item.value.name }}" | ||
+ | when: | ||
+ | - " | ||
+ | - " | ||
+ | with_dict: | ||
+ | - "{{ users }}" | ||
+ | no_log: True | ||
</ | </ | ||
**__Erklärungen__**: | **__Erklärungen__**: | ||
- | * <code yaml>--- ### Add users, groups and creates | + | * <code yaml>--- ### Add, modifies and delete |
Hier ist der Anfang der Konfigurationsdatei im [[https:// | Hier ist der Anfang der Konfigurationsdatei im [[https:// | ||
Zeile 441: | Zeile 471: | ||
* '' | * '' | ||
- | * <code yaml>- name: Ensure | + | * <code yaml>- name: Ensure |
- | group: | + | |
- | gid: "{{ item.value.gid }}" | + | |
- | name: "{{ item.value.group }}" | + | |
- | state: present | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | no_log: True</ | + | |
- | + | ||
- | Es wird sicher gestellt, das eine **Gruppe** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * mit dem Status '' | + | |
- | * '' | + | |
- | durchgeführt wird. | + | |
- | + | ||
- | * <code yaml>- name: Ansible-Host - Ensure user exists. | + | |
user: | user: | ||
- | append: yes | ||
- | comment: "{{ item.value.comment }}" | ||
- | force: yes | ||
- | generate_ssh_key: | ||
- | group: "{{ item.value.group }}" | ||
name: "{{ item.value.name }}" | name: "{{ item.value.name }}" | ||
- | | + | |
- | shell: "{{ item.value.shell }}" | + | state: |
- | ssh_key_comment: | + | when: " |
- | ssh_key_file: | + | |
- | ssh_key_passphrase: | + | |
- | ssh_key_type: | + | |
- | state: | + | |
- | uid: "{{ item.value.uid }}" | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | delegate_to: | + | |
- | no_log: True</ | + | |
- | + | ||
- | Es wird sicher gestellt, das ein **Benutzer** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' | + | |
- | * nur auf dem [[https:// | + | |
- | hinzugefügt wird und nachfolgende Eigenschaften besitzt: | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * mit dem Status '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | durchgeführt wird. | + | |
- | + | ||
- | * <code yaml>- name: Clients - Ensure user exists. | + | |
- | user: | + | |
- | append: yes | + | |
- | comment: "{{ item.value.comment }}" | + | |
- | force: yes | + | |
- | group: "{{ item.value.group }}" | + | |
- | name: "{{ item.value.name }}" | + | |
- | password: "{{ item.value.password | password_hash(' | + | |
- | shell: "{{ item.value.shell }}" | + | |
- | state: present | + | |
- | uid: "{{ item.value.uid }}" | + | |
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
Zeile 514: | Zeile 483: | ||
Es wird sicher gestellt, das ein **Benutzer** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' | Es wird sicher gestellt, das ein **Benutzer** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' | ||
* auf **__allen__ Clients** | * auf **__allen__ Clients** | ||
- | hinzugefügt wird und nachfolgende Eigenschaften besitzt: | ||
- | * '' | ||
- | * '' | ||
* '' | * '' | ||
- | | + | * mit dem Status '' |
- | * '' | + | * '' |
- | | + | |
- | * '' | + | |
* '' | * '' | ||
- | durchgeführt | + | **gelöscht** |
- | * <code yaml>- name: Set exclusive authorized key for users taken from file. | + | :!: **HINWEIS** |
- | authorized_key: | + | |
- | user: "{{ item.value.name }}" | + | |
- | key: "{{ lookup(' | + | |
- | state: present | + | |
- | exclusive: True | + | |
- | with_dict: | + | |
- | | + | |
- | no_log: True</ | + | |
- | Es wird sicher gestellt, das der **öffentliche** **'' | + | :!: **ACHTUNG** - **Alle Dateien im und das $HOME-Verzeichnis |
- | * auf **__allen__ Clients** | + | |
- | hinzugefügt wird und nachfolgende Eigenschaften besitzt: | + | |
- | * '' | + | |
- | * '' | + | |
- | | + | |
- | | + | |
- | * '' | + | |
- | durchgeführt wird. | + | |
- | * <code yaml>- name: Add users to group ' | + | * <code yaml>- name: Ensure group NOT exists, if NOT active. |
- | user: | + | |
- | append: yes | + | |
- | groups: wheel | + | |
- | name: "{{ item.value.name }}" | + | |
- | when: " | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | no_log: True</ | + | |
- | + | ||
- | Es wird sicher gestellt, das ein **Benutzer** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' | + | |
- | * auf **__allen__ Clients** | + | |
- | der Gruppe '' | + | |
- | * '' | + | |
- | * '' | + | |
- | * '' | + | |
- | durchgeführt wird. | + | |
- | + | ||
- | ===== ~/ | + | |
- | + | ||
- | Die Konfigurationsdatei '' | + | |
- | < | + | |
- | $ touch ~/ | + | |
- | </ | + | |
- | + | ||
- | Der Inhalt der Konfigurationsdatei '' | + | |
- | <code yaml> | + | |
- | --- ### Modifies user, groups and ssh-key-pairs. | + | |
- | # | + | |
- | # # ansible-playbook -i / | + | |
- | # | + | |
- | - hosts: all | + | |
- | vars_files: | + | |
- | - / | + | |
- | roles: | + | |
- | - { role: 00_user_mod } | + | |
- | </ | + | |
- | + | ||
- | **__Erklärungen__**: | + | |
- | + | ||
- | * <code yaml>--- ### Modifies user, groups and ssh-key-pairs.</ | + | |
- | + | ||
- | Hier ist der Anfang der Konfigurationsdatei im [[https:// | + | |
- | + | ||
- | * <code yaml> | + | |
- | # # ansible-playbook -i / | + | |
- | #</ | + | |
- | + | ||
- | Ein Kommentar, welcher eine Beschreibung enthält, mit welchen Parametern das **Playbook** ausgeführt werden muss. | + | |
- | + | ||
- | * <code yaml>- hosts: all</ | + | |
- | + | ||
- | Auf welche **hosts** das **Playbook** angewendet werden soll. | + | |
- | + | ||
- | * <code yaml> | + | |
- | + | ||
- | Die Definition, das das **Playbook** nachfolgende Variablen Datei verwenden soll. | + | |
- | + | ||
- | * <code yaml> | + | |
- | + | ||
- | Die Definition, der Variablen Datei welche das **Playbook** verwenden soll. | + | |
- | + | ||
- | * <code yaml> | + | |
- | + | ||
- | Die Definition, das das **Playbook** aus nachfolgender **role** (Rolle) besteht. | + | |
- | + | ||
- | * <code yaml> | + | |
- | + | ||
- | Welche **role** (Rolle) das **Playbook** benutzen soll. | + | |
- | + | ||
- | ==== ~/ | + | |
- | + | ||
- | Die Verzeichnisstruktur für die **role** (Rolle) - '' | + | |
- | < | + | |
- | $ mkdir -p ~/ | + | |
- | </ | + | |
- | + | ||
- | Die Konfigurationsdatei '' | + | |
- | < | + | |
- | $ touch ~/ | + | |
- | </ | + | |
- | + | ||
- | Der Inhalt der Konfigurationsdatei '' | + | |
- | <code yaml> | + | |
- | --- ### Modifies user, groups and ssh-key-pairs. | + | |
- | # | + | |
- | # # ansible-playbook -i / | + | |
- | # | + | |
- | - name: Ensure group exists. | + | |
group: | group: | ||
- | gid: "{{ item.value.gid }}" | ||
name: "{{ item.value.group }}" | name: "{{ item.value.group }}" | ||
- | state: | + | state: |
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
- | no_log: True | + | no_log: True </ |
- | - name: Ansible-Host - Ensure user exists. | + | |
- | user: | + | |
- | append: yes | + | |
- | comment: "{{ item.value.comment }}" | + | |
- | force: yes | + | |
- | generate_ssh_key: | + | |
- | group: "{{ item.value.group }}" | + | |
- | name: "{{ item.value.name }}" | + | |
- | password: "{{ item.value.password | password_hash(' | + | |
- | shell: "{{ item.value.shell }}" | + | |
- | ssh_key_comment: | + | |
- | ssh_key_file: | + | |
- | ssh_key_passphrase: | + | |
- | ssh_key_type: | + | |
- | state: present | + | |
- | uid: "{{ item.value.uid }}" | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | delegate_to: | + | |
- | no_log: True | + | |
- | - name: Clients - Ensure user exists. | + | |
- | user: | + | |
- | append: yes | + | |
- | comment: "{{ item.value.comment }}" | + | |
- | force: yes | + | |
- | group: "{{ item.value.group }}" | + | |
- | name: "{{ item.value.name }}" | + | |
- | password: "{{ item.value.password | password_hash(' | + | |
- | shell: "{{ item.value.shell }}" | + | |
- | state: present | + | |
- | uid: "{{ item.value.uid }}" | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | no_log: True | + | |
- | - name: Set exclusive authorized key for users taken from file. | + | |
- | authorized_key: | + | |
- | user: "{{ item.value.name }}" | + | |
- | key: "{{ lookup(' | + | |
- | state: present | + | |
- | exclusive: True | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | no_log: True | + | |
- | - name: Add users to group ' | + | |
- | user: | + | |
- | append: yes | + | |
- | groups: wheel | + | |
- | name: "{{ item.value.name }}" | + | |
- | when: " | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | no_log: True | + | |
- | </ | + | |
- | **__Erklärungen__**: | + | Es wird sicher gestellt, das eine **Gruppe** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' |
+ | * '' | ||
+ | * mit dem Status '' | ||
+ | * '' | ||
+ | * '' | ||
+ | **gelöscht** wird, **__falls dieser NICHT als aktiv gekennzeichnet ist!__** | ||
- | | + | :!: **HINWEIS** - **Dies bewirkt, das die Gruppe __komplett gelöscht__ wird!** |
- | + | ||
- | Hier ist der Anfang der Konfigurationsdatei im [[https:// | + | |
- | + | ||
- | | + | |
- | # # ansible-playbook -i / | + | |
- | #</ | + | |
- | + | ||
- | Ein Kommentar, welcher eine Beschreibung enthält, mit welchen Parametern | + | |
- | * <code yaml>- name: Ensure group exists. | + | * <code yaml>- name: Ensure group exists, ONLY if active. |
group: | group: | ||
gid: "{{ item.value.gid }}" | gid: "{{ item.value.gid }}" | ||
name: "{{ item.value.group }}" | name: "{{ item.value.group }}" | ||
state: present | state: present | ||
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
Zeile 720: | Zeile 525: | ||
* '' | * '' | ||
* mit dem Status '' | * mit dem Status '' | ||
+ | * '' | ||
* '' | * '' | ||
durchgeführt wird. | durchgeführt wird. | ||
- | * <code yaml>- name: Ansible-Host - Ensure user exists. | + | * <code yaml>- name: Ansible-Host - Ensure user exists, ONLY if active. |
user: | user: | ||
append: yes | append: yes | ||
Zeile 739: | Zeile 545: | ||
state: present | state: present | ||
uid: "{{ item.value.uid }}" | uid: "{{ item.value.uid }}" | ||
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
Zeile 759: | Zeile 566: | ||
* mit dem Status '' | * mit dem Status '' | ||
* '' | * '' | ||
+ | * '' | ||
* '' | * '' | ||
* '' | * '' | ||
durchgeführt wird. | durchgeführt wird. | ||
- | * <code yaml>- name: Clients - Ensure user exists. | + | * <code yaml>- name: Clients - Ensure user exists, ONLY if active. |
user: | user: | ||
append: yes | append: yes | ||
Zeile 774: | Zeile 582: | ||
state: present | state: present | ||
uid: "{{ item.value.uid }}" | uid: "{{ item.value.uid }}" | ||
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
Zeile 788: | Zeile 597: | ||
* mit dem Status '' | * mit dem Status '' | ||
* '' | * '' | ||
+ | * '' | ||
* '' | * '' | ||
durchgeführt wird. | durchgeführt wird. | ||
- | * <code yaml>- name: Set exclusive authorized key for users taken from file. | + | * <code yaml>- name: Set exclusive authorized key for users taken from file, ONLY if active. |
authorized_key: | authorized_key: | ||
user: "{{ item.value.name }}" | user: "{{ item.value.name }}" | ||
Zeile 797: | Zeile 607: | ||
state: present | state: present | ||
exclusive: True | exclusive: True | ||
+ | when: " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
Zeile 808: | Zeile 619: | ||
* mit dem Status '' | * mit dem Status '' | ||
* '' | * '' | ||
+ | * '' | ||
* '' | * '' | ||
durchgeführt wird. | durchgeführt wird. | ||
Zeile 816: | Zeile 628: | ||
groups: wheel | groups: wheel | ||
name: "{{ item.value.name }}" | name: "{{ item.value.name }}" | ||
- | when: " | + | when: |
+ | - " | ||
+ | - " | ||
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
Zeile 825: | Zeile 639: | ||
der Gruppe '' | der Gruppe '' | ||
* '' | * '' | ||
- | * '' | + | * '' |
+ | * '' | ||
* '' | * '' | ||
durchgeführt wird. | durchgeführt wird. | ||
- | ===== ~/ | + | * <code yaml> |
- | + | ||
- | Die Konfigurationsdatei '' | + | |
- | < | + | |
- | $ touch ~/ | + | |
- | </ | + | |
- | + | ||
- | Der Inhalt der Konfigurationsdatei '' | + | |
- | <code yaml> | + | |
- | --- ### Delete users, groups and creates ssh-key-pairs. | + | |
- | # | + | |
- | # # ansible-playbook -i / | + | |
- | # | + | |
- | - hosts: all | + | |
- | vars_files: | + | |
- | - / | + | |
- | roles: | + | |
- | - { role: 00_user_del } | + | |
- | </ | + | |
- | + | ||
- | **__Erklärungen__**: | + | |
- | + | ||
- | * <code yaml>--- ### Delete | + | |
- | + | ||
- | Hier ist der Anfang der Konfigurationsdatei im [[https:// | + | |
- | + | ||
- | * <code yaml> | + | |
- | # # ansible-playbook -i / | + | |
- | #</ | + | |
- | + | ||
- | Ein Kommentar, welcher eine Beschreibung enthält, mit welchen Parametern das **Playbook** ausgeführt werden muss. | + | |
- | + | ||
- | * <code yaml>- hosts: | + | |
- | + | ||
- | Auf welche **hosts** das **Playbook** angewendet werden soll. | + | |
- | + | ||
- | * <code yaml> | + | |
- | + | ||
- | Die Definition, das das **Playbook** nachfolgende Variablen Datei verwenden soll. | + | |
- | + | ||
- | * <code yaml> | + | |
- | + | ||
- | Die Definition, der Variablen Datei welche das **Playbook** verwenden soll. | + | |
- | + | ||
- | * <code yaml> | + | |
- | + | ||
- | Die Definition, das das **Playbook** aus nachfolgender **role** (Rolle) besteht. | + | |
- | + | ||
- | * <code yaml> | + | |
- | + | ||
- | Welche **role** (Rolle) das **Playbook** benutzen soll. | + | |
- | + | ||
- | ==== ~/ | + | |
- | + | ||
- | Die Verzeichnisstruktur für die **role** (Rolle) - '' | + | |
- | < | + | |
- | $ mkdir -p ~/ | + | |
- | </ | + | |
- | + | ||
- | Die Konfigurationsdatei '' | + | |
- | < | + | |
- | $ touch ~/ | + | |
- | </ | + | |
- | + | ||
- | Der Inhalt der Konfigurationsdatei '' | + | |
- | <code yaml> | + | |
- | --- ### Delete users, | + | |
- | # | + | |
- | # # ansible-playbook -i / | + | |
- | # | + | |
- | - name: Ensure user does NOT exists, if NOT active. | + | |
user: | user: | ||
+ | append: no | ||
+ | groups: '' | ||
name: "{{ item.value.name }}" | name: "{{ item.value.name }}" | ||
- | remove: yes | + | |
- | state: absent | + | - " |
- | | + | - " |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | no_log: True | + | |
- | - name: Ensure group does NOT exists, if NOT active. | + | |
- | group: | + | |
- | name: "{{ item.value.group }}" | + | |
- | state: absent | + | |
- | when: " | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | no_log: True | + | |
- | </ | + | |
- | + | ||
- | **__Erklärungen__**: | + | |
- | + | ||
- | * <code yaml>--- ### Delete users, groups and creates ssh-key-pairs.</ | + | |
- | + | ||
- | Hier ist der Anfang der Konfigurationsdatei im [[https:// | + | |
- | + | ||
- | * <code yaml> | + | |
- | # # ansible-playbook -i / | + | |
- | #</ | + | |
- | + | ||
- | Ein Kommentar, welcher eine Beschreibung enthält, mit welchen Parametern das **Playbook** ausgeführt werden muss. | + | |
- | + | ||
- | * <code yaml>- name: Ensure user does NOT exists, if NOT active. | + | |
- | user: | + | |
- | name: " | + | |
- | remove: yes | + | |
- | state: absent | + | |
- | when: " | + | |
with_dict: | with_dict: | ||
- "{{ users }}" | - "{{ users }}" | ||
Zeile 942: | Zeile 658: | ||
Es wird sicher gestellt, das ein **Benutzer** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' | Es wird sicher gestellt, das ein **Benutzer** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' | ||
* auf **__allen__ Clients** | * auf **__allen__ Clients** | ||
+ | von allen Gruppen, auch '' | ||
* '' | * '' | ||
- | * mit dem Status | + | * '' |
- | * '' | + | * '' |
* '' | * '' | ||
- | **gelöscht** | + | durchgeführt |
- | + | ||
- | :!: **HINWEIS** - **Dies bewirkt, das der Benutzer __komplett gelöscht__ wird!** | + | |
- | + | ||
- | :!: **ACHTUNG** - **Alle Dateien im und das $HOME-Verzeichnis des Benutzers werden ebenfalls gelöscht !!!** | + | |
- | + | ||
- | * <code yaml>- name: Ensure group does NOT exists, if NOT active. | + | |
- | group: | + | |
- | name: "{{ item.value.group }}" | + | |
- | state: absent | + | |
- | when: " | + | |
- | with_dict: | + | |
- | - "{{ users }}" | + | |
- | no_log: True</ | + | |
- | + | ||
- | Es wird sicher gestellt, das eine **Gruppe** des **Benutzers** aus dem **dictionary (Wörterbuch)** - '' | + | |
- | * '' | + | |
- | * mit dem Status '' | + | |
- | * '' | + | |
- | * '' | + | |
- | **gelöscht** wird, **__falls dieser NICHT als aktiv gekennzeichnet ist!__** | + | |
- | + | ||
- | :!: **HINWEIS** - **Dies bewirkt, das die Gruppe __komplett gelöscht__ wird!** | + | |
===== Playbook Ausführung ===== | ===== Playbook Ausführung ===== | ||
Zeile 1016: | Zeile 711: | ||
SSH password: | SSH password: | ||
Vault password: | Vault password: | ||
+ | |||
+ | PLAY [all] ********************************************************************* | ||
+ | |||
+ | TASK [Gathering Facts] ********************************************************* | ||
+ | ok: [192.168.1.20] | ||
+ | ok: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Make sure group ' | ||
+ | ok: [192.168.1.20] | ||
+ | ok: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Allow ' | ||
+ | changed: [192.168.1.20] | ||
+ | changed: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Ensure user NOT exists, if NOT active.] ************************ | ||
+ | skipping: [192.168.1.20] => (item=None) | ||
+ | skipping: [192.168.1.20] => (item=None) | ||
+ | skipping: [192.168.1.20] | ||
+ | skipping: [192.168.1.30] => (item=None) | ||
+ | skipping: [192.168.1.30] => (item=None) | ||
+ | skipping: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Ensure group NOT exists, if NOT active.] *********************** | ||
+ | skipping: [192.168.1.20] => (item=None) | ||
+ | skipping: [192.168.1.20] => (item=None) | ||
+ | skipping: [192.168.1.20] | ||
+ | skipping: [192.168.1.30] => (item=None) | ||
+ | skipping: [192.168.1.30] => (item=None) | ||
+ | skipping: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Ensure group exists, ONLY if active.] ************************** | ||
+ | ok: [192.168.1.20] => (item=None) | ||
+ | changed: [192.168.1.30] => (item=None) | ||
+ | changed: [192.168.1.20] => (item=None) | ||
+ | changed: [192.168.1.20] | ||
+ | changed: [192.168.1.30] => (item=None) | ||
+ | changed: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Ansible-Host - Ensure user exists, ONLY if active.] ************ | ||
+ | changed: [192.168.1.20 -> 127.0.0.1] => (item=None) | ||
+ | changed: [192.168.1.30 -> 127.0.0.1] => (item=None) | ||
+ | changed: [192.168.1.20 -> 127.0.0.1] => (item=None) | ||
+ | changed: [192.168.1.20] | ||
+ | changed: [192.168.1.30 -> 127.0.0.1] => (item=None) | ||
+ | changed: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Clients - Ensure user exists, ONLY if active.] ***************** | ||
+ | changed: [192.168.1.20] => (item=None) | ||
+ | changed: [192.168.1.30] => (item=None) | ||
+ | changed: [192.168.1.20] => (item=None) | ||
+ | changed: [192.168.1.20] | ||
+ | changed: [192.168.1.30] => (item=None) | ||
+ | changed: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Set exclusive authorized key for users taken from file, ONLY if active.] *** | ||
+ | ok: [192.168.1.20] => (item=None) | ||
+ | changed: [192.168.1.30] => (item=None) | ||
+ | changed: [192.168.1.20] => (item=None) | ||
+ | changed: [192.168.1.20] | ||
+ | changed: [192.168.1.30] => (item=None) | ||
+ | changed: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Add users to group ' | ||
+ | ok: [192.168.1.20] => (item=None) | ||
+ | skipping: [192.168.1.20] => (item=None) | ||
+ | ok: [192.168.1.20] | ||
+ | changed: [192.168.1.30] => (item=None) | ||
+ | skipping: [192.168.1.30] => (item=None) | ||
+ | changed: [192.168.1.30] | ||
+ | |||
+ | TASK [00_user : Remove users from all groups except the primary group, if set to False.] *** | ||
+ | skipping: [192.168.1.20] => (item=None) | ||
+ | skipping: [192.168.1.30] => (item=None) | ||
+ | ok: [192.168.1.20] => (item=None) | ||
+ | ok: [192.168.1.20] | ||
+ | ok: [192.168.1.30] => (item=None) | ||
+ | ok: [192.168.1.30] | ||
+ | |||
+ | PLAY RECAP ********************************************************************* | ||
+ | 192.168.1.20 | ||
+ | 192.168.1.30 | ||
</ | </ | ||
tachtler/benutzer_mit_ansible_verwalten.1584680528.txt.gz · Zuletzt geändert: 2020/03/20 06:02 von klaus