PLAY PODCASTS
Ansible

Ansible

Ansible

Python Podcast Β· Jochen WersdΓΆrfer / Dominik Geldmacher

August 10, 20222h 6mExplicit

Show Notes

<article class="post-detail"> <header> <h2 class="post-title"> <a href="https://python-podcast.de/show/ansible/">Ansible</a> (click here to comment) </h2> <!-- link is on one line to avoid underlined whitespace --> <div class="post-card-meta"> <a href="https://python-podcast.de/show/ansible/"><time datetime="2022-08-11T00:00:00+02:00">11. August 2022</time>,</a> <span class="author">Jochen</span> </div> </header> <div class="post-body"> <section class="block-overview"> <section class="block-paragraph"> <a href="https://exkulpa.de/maximilian-kindshofer/">Max</a>,&nbsp;<a href="https://twitter.com/oryon_dominik">Dominik</a> und <a href="https://twitter.com/ephes">Jochen</a>&nbsp;unterhalten sich diesmal &uuml;ber&nbsp;<a href="https://www.ansible.com/">Ansible</a>. Dass Ansible selbst in Python geschrieben ist, macht es f&uuml;r Python-Entwickler wie uns nat&uuml;rlich besonders interessant. &quot;Infrastructure as code&quot; machen inzwischen ja irgendwie auch alle - bleibt nur die Frage, ob man <a href="https://www.terraform.io/">Terraform</a>&nbsp;von Ansible aus aufrufen sollte, oder umgekehrt 😏.<br /> <br /> </section> <section class="block-audio"> </section> <section class="block-paragraph"> </section> </section> <section class="block-detail"> <section class="block-paragraph"> &nbsp; <h2><br /> Shownotes</h2> <p>Unsere E-Mail f&uuml;r Fragen, Anregungen &amp; Kommentare: <a href="mailto:[email protected]">[email protected]</a></p> <h3>News aus der Szene</h3> <ul> <li><a href="https://www.djangoproject.com/weblog/2022/aug/03/django-41-released/">Django 4.1 released</a> <ul> <li><a href="https://github.com/jazzband/django-widget-tweaks">django-widget-tweaks</a></li> </ul> </li> <li>Pydantic2 <ul> <li><a href="https://talkpython.fm/episodes/show/376/pydantic-v2-the-plan">Pydantic v2 - The Plan - Podcast Episode</a>&nbsp;</li> <li><a href="https://pydantic-docs.helpmanual.io/blog/pydantic-v2/">Pydantic V2 Plan</a></li> </ul> </li> <li><a href="https://ep2022.europython.eu/">EuroPython 2022</a> <ul> <li><a href="https://ep2022.europython.eu/session/build-a-production-ready-graphql-api-using-python">Build a production ready GraphQL API using Python - Strawberry</a></li> <li><a href="https://ep2022.europython.eu/session/norvig-s-lispy-beautiful-and-illuminating-python-code">Norvig&#39;s lispy: beautiful and illuminating Python code</a></li> <li><a href="https://ep2022.europython.eu/session/python-s-role-in-unlocking-the-secrets-of-the-universe-with-the-james-webb-space-telescope">Python&#39;s role in unlocking the secrets of the Universe with the James Webb Space Telescope</a></li> <li><a href="https://ep2022.europython.eu/session/the-design-of-everyday-apis">The Design of Everyday APIs</a></li> <li><a href="https://ep2022.europython.eu/session/using-python-to-predict-asset-price-reversals">Using python to predict Asset price reversals</a></li> <li><a href="https://ep2022.europython.eu/session/how-to-train-your-graphics-card-to-read">How To Train Your Graphics Card (To Read)</a></li> <li><a href="https://ep2022.europython.eu/session/how-we-are-making-python-3-11-faster">How we are making Python 3.11 faster</a></li> <li><a href="https://ep2022.europython.eu/session/robyn-an-async-python-web-framework-with-a-rust-runtime">Robyn: An async Python web framework with a Rust runtime</a></li> <li><a href="https://ep2022.europython.eu/session/multithreaded-python-without-the-gil">Multithreaded Python without the GIL</a></li> <li><a href="https://ep2022.europython.eu/session/let-s-talk-about-jwt">Let&#39;s talk about JWT</a></li> <li><a href="https://ep2022.europython.eu/session/typing-protocol-type-hints-as-guido-intended">`typing.Protocol`: type hints as Guido intended</a></li> <li><a href="https://ep2022.europython.eu/session/super-search-with-opensearch-and-python">Super Search with OpenSearch and Python</a></li> </ul> </li> </ul> <h3>Ansible</h3> <ul> <li>Ansible ist ein Werkzeug zum managen von Servern.&nbsp;Benannt nach einen Science-Fiktion-Ger&auml;t, dass FTL-Kommunikation m&ouml;glich macht &nbsp;(*Rocannon&rsquo;s World*, by Ursula K Le Guin, 1966). &nbsp;Wird seitdem auch von anderen Authoren in ihren Werken genutzt. &nbsp; <ul> <li><a href="https://www.ansible.com/">ansible</a></li> <li><a href="https://www.chef.io/">chef</a></li> <li><a href="https://puppet.com/">puppet</a></li> <li><a href="https://docs.saltproject.io/en/latest/topics/states/index.html">salt</a></li> </ul> </li> <li><a href="https://www.terraform.io/">Terraform</a></li> <li><a href="https://jinja.palletsprojects.com/en/3.1.x/">Jinja</a></li> <li><a href="https://archlinux.org/">archlinux</a></li> <li><a href="https://www.debian.org/releases/bullseye/">Debian &ldquo;bullseye&rdquo;</a></li> <li><a href="https://github.com/geerlingguy">Jeff Geerling (geerlingguy)</a></li> <li><a href="https://nixos.org/">NixOS</a></li> <li><a href="https://www.docker.com/">docker</a></li> <li><a href="https://python-poetry.org/">poetry</a></li> <li><a href="https://lexfridman.com/john-carmack/">#309 &ndash; John Carmack: Doom, Quake, VR, AGI, Programming, Video Games, and Rockets</a></li> <li><a href="https://12factor.net/">The twelve-factor app</a></li> </ul> <h3>Picks</h3> <ul> <li><a href="https://ibis-project.org/">Ibis</a> <ul> <li><a href="https://youtu.be/7JHqxODJG9k">Two Sigma Presents Pandas at a Crossroads the Past Present and Future with Jeff Reback</a></li> </ul> </li> <li><a href="https://github.com/rixx/django-context-decorator">django-context-decorator</a></li> <li><a href="https://xon.sh/">XONSH is a Python-powered shell</a></li> <li><a href="https://github.com/pytest-dev/pytest-mock">pytest-mock</a> <ul> <li><a href="https://simonwillison.net/2022/Jul/30/psf-board/">Weeknotes: Joining the board of the Python Software Foundation</a></li> </ul> </li> <li><a href="https://github.com/ajalt/fuckitpy">FuckIt.py</a></li> </ul> <h3>Notizen von Max (vielen Dank daf&uuml;r!)</h3> <ul> <li>Ansible ist ein Werkzeug zum managen von Servern.</li> <li>Benannt nach einen Science-Fiktion-Ger&auml;t, dass FTL-Kommunikation m&ouml;glich macht &nbsp;(*Rocannon&rsquo;s World*, by Ursula K Le Guin, 1966). &nbsp;Wird seitdem auch von anderen Authoren in ihren Werken genutzt.</li> <li>Ansible wurde 2015 von Redhat gekauft, vorher Ansible &nbsp;Inc.</li> <li>Deklarativ, man sagt also was man haben m&ouml;chte und Ansible setzt es dann um</li> <li>Idempotent, man kann alles beliebig oft wiederholen ohne negativen Effekt und man landet dann in seinem deklarierten Zustand</li> <li><strong>Aufbau</strong> <ul> <li>Eigentlich wirft Ansible die Befehle in paramiko, einer SSH Lib f&uuml;r Python, und sagt ssh.exec_command(command). Heute ist alles nat&uuml;rlich komplizierter, aber wenn man sich den <a href="http://github.com/ansible/ansible/commit/f31421576b00f0b167cdbe61217c31c21a41ac02?diff=unified">ersten Commit zu Ansible ansieht</a></li> </ul> </li> <li><strong>Inventory</strong> <ul> <li>Hier zieht Ansible sich die Informationen heraus, welche Server bearbeitet werden sollen. Hier kann man dann auch Gruppiern und schon ein paar Variablen deklarieren &nbsp;</li> </ul> </li> <li><strong>Statisches Inventory</strong> <ul> <li>Eine yml-Datei oder INI-Datei in der man seine Server bzw. IPs zu den Servern eintr&auml;gt</li> </ul> </li> <li><strong>Dynamisches Inventory</strong> <ul> <li>Hier kann man seinen Cloudprovider anzapfen oder auch LDAP und weiteres. Hierzu hat man Inventory-Plugins: &nbsp;darunter sind AWS, Docker, Kubernetes, Proxmox, Hetzner DNS -&gt; `ansible-doc -t inventory -l`&nbsp;</li> </ul> </li> <li><strong>Playbook</strong> <ul> <li>Enthalten die Beschreibung, was mit den Hosts im Inventory passieren soll, dazu greifen diese auf <strong>Plays</strong>&nbsp;zur&uuml;ck.</li> <li>&Auml;nlich wie Runbooks oder Checklisten die abzuarbeiten sind, nur automatisch</li> </ul> </li> <li><strong>Plays</strong> <ul> <li>Hier wird beschrieben was ausgef&uuml;hrt werden soll und auf welchem Host das passieren soll</li> <li>Plays haben Jinja2 support - Yeah!</li> <li>Loopen mit `with_items` und dann {{ item.src }} o.&auml;</li> </ul> </li> <li><strong>Tasks</strong> <ul> <li>Eine Aktion die in einem Play passiert</li> </ul> </li> <li><strong>Handlers</strong> <ul> <li>Tasks die von vorherigen Tasks ausgef&uuml;hrt werden, sofern diese den Status auf dem Server ge&auml;ndert hat (&#39;changed&#39;)</li> </ul> </li> <li><strong>Role</strong> <ul> <li><strong>​​​​​​​</strong>Eine Sammlung von Tasks, Variablen, Plugins, Templates und Dateien, die in ein Play importiert werden k&ouml;nnen</li> </ul> </li> <li><strong>Ansible Galaxy</strong> <ul> <li><strong>​​​​​​​</strong>Stellt Sammlungen (<strong>Collections</strong>) von Playbooks aber auch <strong>Rollen</strong>&nbsp;zu Verf&uuml;gung. Etwa Github / PyPI f&uuml;r Ansible</li> <li>Collections k&ouml;nnen per `ansible-galaxy` command installiert werden oder in einem `requirements.yml`-File hinterlegt werden und werden dann bei Ausf&uuml;hrung des Playbooks heruntergeladen &nbsp;<br /> &nbsp;</li> </ul> </li> <li><strong>Privileges</strong> <ul> <li><strong>​​​​​​​</strong>Ansible hat die M&ouml;glichkeit Tasks mit verschiedenen Privilegien, also Benutzeraccounts, auszuf&uuml;hren. Hierzu gibt es die `become`-Direktive. Der Default ist hier `root`. Das Sudo-Passwort kann mit der Flag `-K` abgefragt werden. Oder auch als Variable im Playbook &uuml;bergeben werden. Um Variablen sicher zu speichern hat Ansible <strong>Vaults</strong>. &nbsp;</li> <li>Become und Windows - Zu einer Windowsmaschine kann man sich nur als Priveligierter User verbinden. Become wird hier nur genutzt um noch tiefere Privilegien zu bekommen (`System`) oder um den Nutzer zu wechseln.</li> </ul> </li> <li><strong>Best Practices</strong> <ul> <li><strong>​​​​​​​</strong>Eigentlich wie immer: Verbindung zum Server hin nur mit einem unpreviligierten Account (&auml;h&auml;m Windows *r&auml;usper*)</li> <li>Nur mit den rechten Arbeiten, die man auch braucht - dass passiert eigentlich schon, wenn man mit einem unpriviligierten Account verbindet, denn dann muss man immer `become` unter den Task schreiben und mehr schreiben ist mehr Aufwand und deshalb &uuml;berlegt man schon gleich zweimal ob man wirklich mehr Rechte braucht. &nbsp;</li> <li>Ansible <strong>Vault</strong>&nbsp;benutzen, wenn man mit Passw&ouml;rtern und sonstigen Geheimnissen arbeitet</li> </ul> </li> <li><strong>Skalierung</strong> <ul> <li><strong>​​​​​​​*</strong><em>Grillenzirpen*</em>&nbsp;... aja da gibt es Ansible Tower... wollte ich immer mal reinschauen, aber es ist sehr teuer wenn man es kauft und unm&ouml;glich aufzusetzen wenn man es selbst hosten m&ouml;chte... schon etwas komisch, wenn man doch einfach ein Ansible Playbook schreiben k&ouml;nnte &nbsp;</li> </ul> </li> <li><strong>Unterschiedliche Betriebssysteme</strong> <ul> <li><strong>​​​​​​​</strong>Linux/Unix und die verschiedenen Distributionen</li> <li>Hier muss darauf geachtet werden, dass man den richtigen Packagemanager erwischt und die Dateien am vermuteten Ort liegen. Mit `ansible_os_familiy` kann man dann &uuml;ber die`when` Direktive in unterschiedliche Entscheidungsb&auml;ume abgleiten &nbsp;</li> </ul> </li> <li><strong>Windows</strong> <ul> <li><strong>​​​​​​​</strong>Hier wird anstelle SSH und der Shell PowerShell genutzt</li> </ul> </li> <li><strong>Network Automation</strong><strong>​​​​​​​</strong> <ul> <li><a href="https://www.ansible.com/integrations/networks">Liste der Integrationen</a></li> </ul> </li> <li><strong>Terraform und Ansible</strong> <ul> <li><strong>​​​​​​​</strong>Terraform baut dir die Infrastruktur auf und Ansible konfiguriert dir diese. Dabei kann Ansible auch wieder Terraform aufrufen usw..</li> <li>ch will nie wieder zur&uuml;ck zu Bash, aber ich will etwas local laufen lassen:&nbsp;&nbsp;`#!/usr/bin/env ansible-playbook` und im Play:<br /> &nbsp;&nbsp;```<br /> &nbsp;&nbsp; &nbsp;&nbsp;---<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;- name: &quot;Ansibel Local&quot;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hosts: localhost<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;connection: local&nbsp;<br /> &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tasks:<br /> &nbsp;&nbsp;```<br /> &nbsp;</li> </ul> </li> <li><a href="https://yt.bithive.space/playlist?list=PL2_OBreMn7FqZkvMYt6ATmgC0KAGGJNAN">Liste von Videotutorials</a></li> </ul> <br /> </section> </section> </div> </article>

Topics

ansiblepythonterraformdocker