| Beide Seiten der vorigen Revision Vorhergehende Überarbeitung Nächste Überarbeitung | Vorhergehende Überarbeitung |
| linux:ansible:playbook_example_08 [01.06.2024 13:39. ] – [Script anlegen] django | linux:ansible:playbook_example_08 [26.07.2025 15:58. ] (aktuell) – [Fazit und Ausblick] django |
|---|
| |
| === Script Beschreibung === | === Script Beschreibung === |
| Mit Hilfe des Playbooks werden alle wesentlichen Konfigurationsoptionen definiert, die im Kapitel **[[first#grund-_konfiguration|(Grund-)Konfiguration - (Grund-)Konfiguration]]** detailliert beschrieben und besprochen wurden. Die Details zur spezifischen **Ansible-Vault** Konfiguration finden sich im Kapitel **[[playbook_example_07#ansible-vault_in_verbindung_mit_ansible-playbook|Ansible - erweitertes Konfigurationsbeispiel 7: Ansible Vault - ansible-vault in Verbindung mit ansible-playbook]]**. | Mit Hilfe des Playbooks werden für unseren Admin-User auf unserem Arch-Linux Host alle wesentlichen Konfigurationsoptionen definiert, die im Kapitel **[[first#grund-_konfiguration|(Grund-)Konfiguration - (Grund-)Konfiguration]]** detailliert beschrieben und besprochen wurden. Die Details zur spezifischen **Ansible-Vault** Konfiguration finden sich im Kapitel **[[playbook_example_07#ansible-vault_in_verbindung_mit_ansible-playbook|Ansible - erweitertes Konfigurationsbeispiel 7: Ansible Vault - ansible-vault in Verbindung mit ansible-playbook]]**. |
| |
| Nacheinander werden folgende Punkte abgearbeitet: | Nacheinander werden folgende Punkte abgearbeitet: |
| - Ermitteln des angemeldeten (Admin-)Usernamens **''admin_user''**, der für die weitere Programmlauf benötigt wird. | - Ermitteln des angemeldeten (Admin-)Usernamens **''admin_user''**, der für die weitere Programmlauf benötigt wird. |
| - Abfrage des Passwortes für den **Password-Store** und des **''ansible_become_password''**, damit dies bei der weiteren Abarbeitung des Ansible-Playbooks entsprechend verschlüsselt in einer **vault**-Datei sicher abgelegt werden kann. | - Abfrage des Passwortes für den **Password-Store** und des **''ansible_become_password''**, damit dies bei der weiteren Abarbeitung des Ansible-Playbooks entsprechend verschlüsselt in einer **vault**-Datei sicher abgelegt werden kann. |
| - Prüfen, ob die Konfigurationsdatei **''/etc/ansible.cfg''** vorhanden ist und ggf. das Playbook geordnet abbrechen falls dies nicht der Fall sein sollte. | - Generieren der Ansible Konfigurationsdatei **''/etc/ansible.cfg''** mit Hilfe von **''ansible-config init --disabled > ~/.ansible.cfg''** |
| - Kopieren der Ansible Konfigurationsdatei **''/etc/ansible.cfg''** nach **''~/.ansible.cfg''**. | |
| - Setzen der Ansible-Konfigurationsoptionen | - Setzen der Ansible-Konfigurationsoptionen |
| * **''interpreter_python = auto_silent''** | * **''interpreter_python = auto_silent''** |
| * **''vault_password_file = ~/bin/ansible_vault_password''** | * **''vault_password_file = ~/bin/ansible_vault_password''** |
| - Ansible Directory Layout anlegen und anschliessend | - Ansible Directory Layout anlegen und anschliessend |
| - Ansible Directory Layout mit dummy-files main.yml befüllen. | - Ansible Directory Layout mit dummy-files **''.gitkeep''** befüllen. |
| - Installation des Passwort-Managers **''pass''** | - Installation des Passwort-Managers **''pass''** |
| - vault-Wrapperscript im **''bin''** Verzeichnis des Admins ablegen und ggf. das zugehörige Verzeichnis anlegen. | - vault-Wrapperscript im **''bin''** Verzeichnis des Admins ablegen und ggf. das zugehörige Verzeichnis anlegen. |
| - Ansible-Vault Datei, die zuvor angelegt wurde, mit dem Ansible-Vault-Passwort sicher verschlüsseln. | - Ansible-Vault Datei, die zuvor angelegt wurde, mit dem Ansible-Vault-Passwort sicher verschlüsseln. |
| - Im Inventory die Definitionen zu privilege_escalation anlegen und auch hier ggf. ein bereits existierende Konfigurationsdatei vorher löschen. | - Im Inventory die Definitionen zu privilege_escalation anlegen und auch hier ggf. ein bereits existierende Konfigurationsdatei vorher löschen. |
| | - Installation und Konfiguration des Ansible Stdout Compact Logger unter Arch Linux |
| | * **''stdout_callback=anstomlog''** |
| | * **''callback_plugins = ~/.ansible/plugins/callback"''** |
| | |
| |
| === Script starten === | === Script starten === |
| Das Ansible-Playbook lässt sich wie folgt auf dem Ansible-Controll-Host bzw. der Admin-Workstation aufrufen: | Das Ansible-Playbook lässt sich wie folgt auf dem Ansible-Controll-Host bzw. der Admin-Workstation aufrufen: |
| |
| $ ansible-playbook ~/ansible/playbooks/ansible_grundconfig_v2.yml -K | $ ansible-playbook ~/devel/ansible/playbooks/ansible_grundconfig_v2.yml -K |
| | |
| <html> | |
| <pre class="code"> | |
| <font style="color: rgb(0, 0, 0)">BECOME password: </font> | |
| <font style="color: rgb(170, 127, 166)"><b>[WARNING]: No inventory was parsed, only implicit localhost is available | |
| [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'</b></font> | |
| <font style="color: rgb(0, 0, 0)">Enter password for password-store?: | |
| Retype password for password-store?: | |
| Enter become-password for sudo?: | |
| Retype become-password for sudo?: | |
| | |
| PLAY [ansible_grundconfig_v2.yml] ************************************************************************************************* | |
| | |
| TASK [Gathering Facts] ************************************************************************************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Playbooklauf abbrechen sofern die beiden eigegebenen Passwörter nicht übereinstimmen!] **************************************</font> | |
| <font style="color: rgb(43, 100, 164)">skipping: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Playbooklauf abbrechen sofern die beiden eigegebenen Passwörter nicht übereinstimmen!] **************************************</font> | |
| <font style="color: rgb(43, 100, 164)">skipping: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Ansible Konfigurationsdatei /etc/ansible/ansible.cfg vorhanden?] ************************************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Fehlerhinweis im Fehlerfall ausgeben] ***************************************************************************************</font> | |
| <font style="color: rgb(43, 100, 164)">skipping: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Ansible Konfigurationsverzeichnis in das User/Admin-Verzeichnis kopieren] ***************************************************</font> | |
| <font style="color: rgb(196, 160, 0)">changed: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Ansible Konfiguration anpassen] *********************************************************************************************</font> | |
| <font style="color: rgb(196, 160, 0)">changed: [localhost] => (item={'regexp': '^\\[defaults\\]', 'line': '[defaults]\n# Generated by Ansible on 2022-09-22, do not edit manually!\n# default:\ninterpreter_python = auto_silent'}) | |
| changed: [localhost] => (item={'regexp': '^\\#inventory = /etc/ansible/hosts', 'line': '# Generated by Ansible on 2022-09-22, do not edit manually!\n# default: #inventory = /etc/ansible/hosts\ninventory = /home/django/ansible/inventories/production'}) | |
| changed: [localhost] => (item={'regexp': '^\\#roles_path = /etc/ansible/roles', 'line': '# Generated by Ansible on 2022-09-22, do not edit manually!\n# default: #roles_path = /etc/ansible/roles\nroles_path = ~/ansible/roles'}) | |
| changed: [localhost] => (item={'regexp': '^\\#vault_password_file = /path/to/vault_password_file', 'line': '# Generated by Ansible on 2022-09-22, do not edit manually!\n# default: #vault_password_file = /path/to/vault_password_file\nvault_password_file = ~/bin/ansible_vault_password'})</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Ansible Directory Layout anlegen] *******************************************************************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost] => (item={'directory': 'filter_plugins/'}) | |
| ok: [localhost] => (item={'directory': 'library/'}) | |
| ok: [localhost] => (item={'directory': 'module_utils/'}) | |
| ok: [localhost] => (item={'directory': 'playbooks/'}) | |
| ok: [localhost] => (item={'directory': 'inventories/production/group_vars/'}) | |
| ok: [localhost] => (item={'directory': 'inventories/production/host_vars/'}) | |
| ok: [localhost] => (item={'directory': 'inventories/staging/group_vars/'}) | |
| ok: [localhost] => (item={'directory': 'inventories/staging/host_vars/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/defaults/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/files/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/handlers/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/library/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/lookup_plugins/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/meta/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/module_utils/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/tasks/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/templates/'}) | |
| ok: [localhost] => (item={'directory': 'roles/common/vars/'})</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Ansible Directory Layout mit dummy-files main.yml befüllen] ***************************************************************</font> | |
| <font style="color: rgb(196, 160, 0)">changed: [localhost] => (item={'file': 'filter_plugins/main.yml'}) | |
| changed: [localhost] => (item={'file': 'library/main.yml'}) | |
| changed: [localhost] => (item={'file': 'module_utils/main.yml'}) | |
| changed: [localhost] => (item={'file': 'inventories/production/hosts'}) | |
| changed: [localhost] => (item={'file': 'inventories/production/group_vars/main.yml'}) | |
| changed: [localhost] => (item={'file': 'inventories/production/host_vars/main.yml'}) | |
| changed: [localhost] => (item={'file': 'inventories/staging/hosts'}) | |
| changed: [localhost] => (item={'file': 'inventories/staging/group_vars/main.yml'}) | |
| changed: [localhost] => (item={'file': 'inventories/staging/host_vars/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/defaults/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/files/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/handlers/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/library/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/lookup_plugins/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/meta/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/module_utils/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/tasks/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/templates/main.yml'}) | |
| changed: [localhost] => (item={'file': 'roles/common/vars/main.yml'})</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Passwort-Manager pass installieren] ***********************************************************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Verzeichnis ~/bin anlegen] ********************************************************************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [vault-Wrapperscript anlegen] ******************************************************************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Sicherstellen dass das pass Store-Verzeichnis nicht existiert] ********************************************************</font> | |
| <font style="color: rgb(196, 160, 0)">changed: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Pass-Store Passwort ablegen] ******************************************************************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Sicherstellen dass das File für das verschlüsselte become-password noch nicht existiert] ******************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Ansible Become Password für sudo Rechteerweiterung anlegen] ***********************************************************</font> | |
| <font style="color: rgb(196, 160, 0)">changed: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Ansible Become Password mit ansible-vault verschlüsseln] **************************************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Sicherstellen dass das File mit der Ansible-Konfiguration nicht existiert] ********************************************</font> | |
| <font style="color: rgb(25, 100, 5)">ok: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| TASK [Ansible Konfigurationsdatei mit den Definitionen zu privilege_escalation anlegen] *************************************</font> | |
| <font style="color: rgb(196, 160, 0)">changed: [localhost]</font> | |
| <font style="color: rgb(0, 0, 0)"> | |
| PLAY RECAP ********************************************************************************************************************</font> | |
| <font style="color: rgb(196, 160, 0)">localhost</font><font style="color: rgb(0, 0, 0)"> : </font><font style="color: rgb(25, 100, 5)">ok=16 </font><font style="color: rgb(196, 160, 0)">changed=6 </font><font style="color: rgb(0, 0, 0)">unreachable=0 failed=0 </font><font style="color: rgb(43, 100, 164)">skipped=3 </font><font style="color: rgb(0, 0, 0)">rescued=0 ignored=0</font> | |
| | |
| </pre> | |
| </html> | |
| |
| {{ :linux:ansible:ansible-krypto-stick.png?nolink&200|Bild: Ansible NitroKey Start}}Beim Aufruf eines Ansible-Playbooks liest das Programm **''ansible-playbook''** alle benötigten Dateien ein. Zum Abarbeiten benötigt Ansible natürlich die temporär entschlüsselten Informationen. Damit Ansible nun die verschlüsselten Informationen herankommt, benötigt Ansible natürlich vorübergehend das Vault-Passwort/-Passphrase, welches sich nun selbst verschlüsselt in einem Ansible-Vault befindet. Durch den Passwortmanager **''pass''** und unserem PGP-Schlüssel kommen wir nun direkt zu dem **Ansible Vault Passwort**. Wir brauchen also nur einmal das für den PGP zugehörige Passwort oder im Falle der Verwendung eines Security-Hardware-Devices wie eines **[[https://shop.nitrokey.com/de_DE/shop/product/nksa-nitrokey-start-6|Nitrokey Start]]**. | {{ :linux:ansible:ansible-krypto-stick.png?nolink&200|Bild: Ansible NitroKey Start}}Beim Aufruf eines Ansible-Playbooks liest das Programm **''ansible-playbook''** alle benötigten Dateien ein. Zum Abarbeiten benötigt Ansible natürlich die temporär entschlüsselten Informationen. Damit Ansible nun die verschlüsselten Informationen herankommt, benötigt Ansible natürlich vorübergehend das Vault-Passwort/-Passphrase, welches sich nun selbst verschlüsselt in einem Ansible-Vault befindet. Durch den Passwortmanager **''pass''** und unserem PGP-Schlüssel kommen wir nun direkt zu dem **Ansible Vault Passwort**. Wir brauchen also nur einmal das für den PGP zugehörige Passwort oder im Falle der Verwendung eines Security-Hardware-Devices wie eines **[[https://shop.nitrokey.com/de_DE/shop/product/nksa-nitrokey-start-6|Nitrokey Start]]**. |
| ===== Fazit und Ausblick ===== | ===== Fazit und Ausblick ===== |
| <WRAP center round info 60%> | <WRAP center round info 60%> |
| Wir haben nun Dank der beiden gezeigten Ansible-Playbooks zur Konfiguration unserer Ansible-Umgebung die Möglichkeit, jederzeit bei Bedarf einen weiteren Admin zu befähigen bzw. eine bestehende Umgebung erneut auszurollen. Somit können wir nun mit **Ansible-Vault** vertrauliche Informationen in unseren Playbooks bzw. im Inventory ablegen. Diese werden als krypted **AES256** Daten abgelegt und können dadurch auch jederzeit in einem verteiltem Versionskontrollsystem wie **[[ https://git-scm.com/|git]]** vorgehalten werden. Durch Nutzung des Passwort-Manager **''pass''** wird die Handhabung soweit vereinfacht, so dass der Admin auch ohne grosse Not mehrmals hintereinander Ansible-Playbooks ausführen kann, ohne sich durch zigfache Eingabe von Passworten sich selbst das Leben allzu schwer zu machen! | Wir haben nun Dank der beiden gezeigten Ansible-Playbooks zur Konfiguration unserer Ansible-Umgebung die Möglichkeit, jederzeit bei Bedarf einen weiteren Admin zu befähigen bzw. eine bestehende Umgebung erneut auszurollen. Somit können wir nun mit **Ansible-Vault** vertrauliche Informationen in unseren Playbooks bzw. im Inventory ablegen. Diese werden als krypted **AES256** Daten abgelegt und können dadurch auch jederzeit in einem verteiltem Versionskontrollsystem wie **[[ https://git-scm.com/|git]]** vorgehalten werden. Durch Nutzung des Passwort-Manager **''pass''** wird die Handhabung soweit vereinfacht, so daß der Admin auch ohne große Not mehrmals hintereinander Ansible-Playbooks ausführen kann, ohne sich durch zigfache Eingabe von Paßworten sich selbst das Leben allzu schwer zu machen! |
| </WRAP> | </WRAP> |
| |