{"id":2323,"date":"2024-03-21T17:51:37","date_gmt":"2024-03-21T15:51:37","guid":{"rendered":"https:\/\/www.fotoandnet.de\/wp\/?p=2323"},"modified":"2024-10-25T14:21:37","modified_gmt":"2024-10-25T12:21:37","slug":"einrichtung-des-ansbiles-im-lxc-container","status":"publish","type":"post","link":"http:\/\/www.fotoandnet.de\/wp\/?p=2323","title":{"rendered":"Ansibile Inventory Setup im LXC Container"},"content":{"rendered":"\n<p>Im letzten Artikel habe ich den Ansible und Semaphore LXC Container aufgesetzt. Zeit diesen so zu konfigurieren, dass wir zuerst einmal mit dem Ansible auf andere Komponenten zugreifen k\u00f6nnen und dann auch die gew\u00fcnschten Playbooks schreiben und nutzen k\u00f6nnen. Zuerst m\u00f6chte ich aus meiner lokalen Bash ohne grosses h\u00e4ngen und w\u00fcrgen auf den Container per SSH zugreifen k\u00f6nnen. Auf dem LXC Container existiert zu erst nur der User ROOT und genau mit diesem m\u00f6chte ich mich auf Port 22 einloggen. Als Loglevel h\u00e4tte ich gerne nur INFOs und wichtigere Meldungen. Das alles soll logischerweise per IPv6 erfolgen und ich w\u00fcrde gerne mit dem Kurznamen &#8222;rooti&#8220; zu Zugriff herstellen, ohne in der \/etc\/hosts oder dem DNS herum Spielen zu m\u00fcssen.<\/p>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Lokale SSH-Config und Login Test<\/mark><\/strong><\/p>\n\n\n\n<p>Also erzeuge ich mir auf meinem lokalen Linux PC einen Eintrag f\u00fcr den Host ansi und gebe dort die ganzen Werte an. Da geht nat\u00fcrlich noch viel mehr, aber f\u00fcr meine Zwecke ist das erst einmal ausreichend. Wer gerne unterschiedliche SSH-Keys pro Host nimmt, wird diese Datei nat\u00fcrlich zur Gen\u00fcge kennen, denn genau hier lassen sich die Sessions-Keys f\u00fcr den jeweiligen Host definieren. \ud83d\ude09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>|17:21:57|eric@cthulhu:&#091;~]&gt; more .ssh\/config\n \nHost rooti\n        Hostname fda0:d594:f020:ffff::55\n        User root\n        Compression yes\n        LogLevel info\n<\/code><\/pre>\n\n\n\n<p>Dann werde ich mal testen ob ich mit dem Befehl &#8222;ssh rooti&#8220; eine Session per IPv6 mit dem Username ROOT \u00f6ffne.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>|17:22:02|eric@cthulhu:&#091;~]&gt; ssh rooti\n\nThe authenticity of host 'fda0:d594:f020:ffff::55 (fda0:d594:f020:ffff::55)' can't be established.\nED25519 key fingerprint is SHA256:kZYWZhePmRFHQGY3Y2KhFVWCv2311CH6zUWvIGD85Ck.\nThis key is not known by any other names.\nAre you sure you want to continue connecting (yes\/no\/&#091;fingerprint])? yes\n\nWarning: Permanently added 'fda0:d594:f020:ffff::55' (ED25519) to the list of known hosts.\n\nroot@fda0:d594:f020:ffff::55's password: Aligator3\n\nWelcome to Ct101-ansible, TurnKey GNU\/Linux 17.1 (Debian 11\/Bullseye)\n\n  System information for Tue Mar 19 13:25:50 2024 (UTC+0000)\n  \n    System load:  0.00              Memory usage:  3.9%\n    Processes:    30                Swap usage:    0.0%\n    Usage of \/:   2.0% of 50.00GB   IP address for eth0: 192.168.2.55\n   \nLinux CT101-Ansible 6.5.13-1-pve #1 SMP PREEMPT_DYNAMIC PMX 6.5.13-1 (2024-02-05T15:50Z) x86_64\nLast login: never\n\nroot@CT101-Ansible ~# \n<\/code><\/pre>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\">IPv6-Test <\/mark><\/strong><\/p>\n\n\n\n<p>Ich bin also auf dem Host &#8222;rooti&#8220; angekommen, werfen wir noch einen Blick auf die Session selbst (also IPv4 oder IPv6).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@CT101-Ansible ~# netstat -tnpa | grep 'ESTABLISHED.*sshd'\n\ntcp6       0      0 fda0:d594:f020:ffff::22 fda0:d594:f020:ff:51474 ESTABLISHED 4145\/sshd: root@pts \n\nroot@CT101-Ansible ~# ss | grep -i ssh\n\ntcp   ESTAB 0      0         &#091;fda0:d594:f020:ffff::55]:ssh     &#091;fda0:d594:f020:ffff:e7a4:7470:c426:ceae]:51474\n\n<span style=\"font-family:monospace\"><span style=\"font-weight:bold;color:#ffff54;background-color:#ffffff\">root@CT101-Ansible <\/span><span style=\"font-weight:bold;color:#5454ff;background-color:#ffffff\">~<\/span><span style=\"color:#000000;background-color:#ffffff\"># journalctl -fu ssh\n<\/span>-- Journal begins at Sat 2024-03-19 15:16:34 UTC. --\nMar 19 15:16:34 CT101-Ansible sshd&#091;4142]: Connection closed by fda0:d594:f020:ffff:e7a4:7470:c426:ceae port 50160 &#091;preauth]\nMar 19 15:25:50 CT101-Ansible sshd&#091;4145]: Accepted password for root from fda0:d594:f020:ffff:e7a4:7470:c426:ceae port 51474 ssh2\nMar 19 15:25:50 CT101-Ansible sshd&#091;4145]: pam_unix(sshd:session): session opened for user root(uid=0) by (uid=0)\n<\/span><\/code><\/pre>\n\n\n\n<p>Ich hab hier mal die drei g\u00e4ngigen Befehle netstat, ss und journalctl genommen. Einer davon sollte auf jedem Linux Type eigentlich vorhanden sein.<\/p>\n\n\n\n<p>Es ist gut zu erkennen, dass eine IPv6 Session f\u00fcr SSH genutzt wurde, damit ist meine .ssh\/config funktional und kann so bleiben. <\/p>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Ansible Check<\/mark><\/strong><\/p>\n\n\n\n<p>Dann m\u00f6chte ich mir das im letzten Artikel installierte Ansible doch mal etwas genauer ansehen, also welche Version habe ich und welche Plugins sind mit installiert worden. Fangen wir beim Versions Check an.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@CT101-Ansible ~# ansible --version\n\nansible 2.10.17\n  config file = \/etc\/ansible\/ansible.cfg\n  configured module search path = &#091;'\/root\/library', '\/usr\/share\/ansible\/library']\n  ansible python module location = \/usr\/local\/lib\/python3.9\/dist-packages\/ansible\n  executable location = \/usr\/local\/bin\/ansible\n  python version = 3.9.2 (default, Feb 28 2021, 17:03:44) &#091;GCC 10.2.1 20210110]\n<\/code><\/pre>\n\n\n\n<p>Und nun noch die Pr\u00fcfung der mit installierten Connection Plugins.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@CT101-Ansible ~# ansible-doc -t connection -l\n\nansible.netcommon.httpapi      Use httpapi to run command on network appliances                                                                        \nansible.netcommon.libssh       (Tech preview) Run tasks using libssh for ssh connection                                                                \nansible.netcommon.napalm       Provides persistent connection using NAPALM                                                                             \nansible.netcommon.netconf      Provides a persistent connection using the netconf protocol                                                             \nansible.netcommon.network_cli  Use network_cli to run command on network appliances                                                                    \nansible.netcommon.persistent   Use a persistent unix socket for connection                                                                             \ncommunity.aws.aws_ssm          execute via AWS Systems Manager                                                                                         \ncommunity.docker.docker        Run tasks in docker containers                                                                                          \ncommunity.docker.docker_api    Run tasks in docker containers                                                                                          \ncommunity.general.chroot       Interact with local chroot                                                                                              \ncommunity.general.docker       Run tasks in docker containers                                                                                          \ncommunity.general.funcd        Use funcd to connect to target                                                                                          \ncommunity.general.iocage       Run tasks in iocage jails                                                                                               \ncommunity.general.jail         Run tasks in jails                                                                                                      \ncommunity.general.lxc          Run tasks in lxc containers via lxc python library                                                                      \ncommunity.general.lxd          Run tasks in lxc containers via lxc CLI                                                                                 \ncommunity.general.oc           Execute tasks in pods running on OpenShift                                                                              \ncommunity.general.qubes        Interact with an existing QubesOS AppVM                                                                                 \ncommunity.general.saltstack    Allow ansible to piggyback on salt minions                                                                              \ncommunity.general.zone         Run tasks in a zone instance                                                                                            \ncommunity.kubernetes.kubectl   Execute tasks in pods running on Kubernetes                                                                             \ncommunity.libvirt.libvirt_lxc  Run tasks in lxc containers via libvirt                                                                                 \ncommunity.libvirt.libvirt_qemu Run tasks on libvirt\/qemu virtual machines                                                                              \ncommunity.okd.oc               Execute tasks in pods running on OpenShift                                                                              \ncommunity.vmware.vmware_tools  Execute tasks inside a VM via VMware Tools                                                                              \ncontainers.podman.buildah      Interact with an existing buildah container                                                                             \ncontainers.podman.podman       Interact with an existing podman container                                                                              \nlocal                          execute on controller                                                                                                   \nlxc_ssh                        connect via ssh and lxc to remote lxc guest                                                                             \nparamiko_ssh                   Run tasks via python ssh (paramiko)                                                                                     \npsrp                           Run tasks over Microsoft PowerShell Remoting Protocol                                                                   \nssh                            connect via ssh client binary                                                                                           \nwinrm                          Run tasks over Microsoft's WinRM     <\/code><\/pre>\n\n\n\n<p>Sowie die mit installierten Inventoty Plugins.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>root@CT101-Ansible ~# ansible-doc -t inventory -l\n      \nadvanced_host_list                   Parses a 'host list' with ranges                                                                                  \namazon.aws.aws_ec2                   EC2 inventory source                                                                                              \namazon.aws.aws_rds                   rds instance source                                                                                               \nauto                                 Loads and executes an inventory plugin specified in a YAML config                                                 \nawx.awx.tower                        Ansible dynamic inventory plugin for Ansible Tower                                                                \nazure.azcollection.azure_rm          Azure Resource Manager inventory plugin                                                                           \ncloudscale_ch.cloud.inventory        cloudscale.ch inventory source                                                                                    \ncommunity.docker.docker_containers   Ansible dynamic inventory plugin for Docker containers                                                            \ncommunity.docker.docker_machine      Docker Machine inventory source                                                                                   \ncommunity.docker.docker_swarm        Ansible dynamic inventory plugin for Docker swarm nodes                                                           \ncommunity.general.cobbler            Cobbler inventory source                                                                                          \ncommunity.general.docker_machine     Docker Machine inventory source                                                                                   \ncommunity.general.docker_swarm       Ansible dynamic inventory plugin for Docker swarm nodes                                                           \ncommunity.general.gitlab_runners     Ansible dynamic inventory plugin for GitLab runners                                                               \ncommunity.general.kubevirt           KubeVirt inventory source                                                                                         \ncommunity.general.linode             Ansible dynamic inventory plugin for Linode                                                                       \ncommunity.general.nmap               Uses nmap to find hosts to target                                                                                 \ncommunity.general.online             Scaleway (previously Online SAS or Online.net) inventory source                                                   \ncommunity.general.proxmox            Proxmox inventory source                                                                                          \ncommunity.general.scaleway           Scaleway inventory source                                                                                         \ncommunity.general.stackpath_compute  StackPath Edge Computing inventory source                                                                         \ncommunity.general.virtualbox         virtualbox inventory source                                                                                       \ncommunity.hrobot.robot               Hetzner Robot inventory source                                                                                    \ncommunity.kubernetes.k8s             Kubernetes (K8s) inventory source                                                                                 \ncommunity.kubernetes.openshift       OpenShift inventory source                                                                                        \ncommunity.kubevirt.kubevirt          KubeVirt inventory source                                                                                         \ncommunity.libvirt.libvirt            Libvirt inventory source                                                                                          \ncommunity.okd.openshift              OpenShift inventory source                                                                                        \ncommunity.vmware.vmware_vm_inventory VMware Guest inventory source                                                                                     \nconstructed                          Uses Jinja2 to construct vars and groups based on existing inventory                                              \ngenerator                            Uses Jinja2 to construct hosts and groups from patterns                                                           \ngoogle.cloud.gcp_compute             Google Cloud Compute Engine inventory source                                                                      \nhetzner.hcloud.hcloud                Ansible dynamic inventory plugin for the Hetzner Cloud                                                            \nhost_list                            Parses a 'host list' string                                                                                       \nini                                  Uses an Ansible INI file as inventory source                                                                      \nnetbox.netbox.nb_inventory           NetBox inventory source                                                                                           \nngine_io.vultr.vultr                 Vultr inventory source                                                                                            \nopenstack.cloud.openstack            OpenStack inventory source                                                                                        \novirt.ovirt.ovirt                    oVirt inventory source                                                                                            \nscript                               Executes an inventory script that returns JSON                                                                    \nservicenow.servicenow.now            ServiceNow Inventory Plugin                                                                                       \ntheforeman.foreman.foreman           Foreman inventory source                                                                                          \ntoml                                 Uses a specific TOML file as an inventory source                                                                  \nyaml                                 Uses a specific YAML file as an inventory source     <\/code><\/pre>\n\n\n\n<p>Okay, in Debian 11 (nicht mehr ganz Tau frisch) ist die Ansible Community Version 2.10.17 dabei (gut abgehangen). Als Plugins habe ich in jedem Falle Network_Cli dabei (ssh), was insgesammt f\u00fcr meine Belange ausreichend erscheint.<\/p>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Ansible User anlegen anlegen<\/mark><\/strong><\/p>\n\n\n\n<p>Nat\u00fcrliche m\u00f6chte ich nicht mit dem User Root arbeiten, um Ansible zu nutzen und auf andere Systeme zuzugreifen. Es ist also an der Zeit einen User daf\u00fcr anzulegen. Ich w\u00e4hle hier f\u00fcr den User Name &#8222;ansible&#8220;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>useradd -m -G users,sudo -s \/bin\/bash ansible\npasswd ansible\n&lt;starkes Passwort&gt;\nnano \/etc\/sudoers\n%sudo   ALL=(ALL:ALL) NOPASSWD:ALL\n\nAlle weiteren Arbeiten werden mit dem User Ansible durchgef\u00fchrt.<\/code><\/pre>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\"><em>Ansible Host Inventory anlegen<\/em><\/mark><\/strong><\/p>\n\n\n\n<p>Damit Ansible Control Node auf die Hosts zugreifen kann, bedarf es des einer Inventar-Liste in der Form eines f\u00fcr Ansible lesbaren Inventorys. Dieses Inventory kann nach meinem Wissen an unterschiedlichen stellen liegen und wird in folgender Reihenfolge in der Wertigkeit absteigend abgearbeitet:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Durch Angabe innerhalb der Befehlsoption, z. B. ansible-playbook -i filepath<\/li>\n\n\n\n<li>Die Konfigurationsdatei ansible.cfg: [defaults] inventory = \/some\/other\/filepath<\/li>\n\n\n\n<li>Der Standardspeicherort: \/etc\/ansible\/hosts<\/li>\n<\/ol>\n\n\n\n<p>Um sicher zu gehen, dass Ansible auf der Komandozeile, sowie Semaphore das selbe Inventory nutzt, werde ich mit der \/etc\/ansible\/hosts arbeiten. Diese wiederum kann dann in zwei verschiedenen Arten geschrieben sein, entweder im INI-Format oder als YAML-File. Ich bevorzuge das YAML-Format, da ich glaube, dass das langfristig existieren wird. \ud83d\ude09<\/p>\n\n\n\n<p>Ich teile das Inventory dabei in die drei Gruppen Containers, Physicals und Storage ein. Diese Gruppen fasse ich dann in der Metagruppe Server zusammen. Eventuel kommen sp\u00e4ter noch weitere Gruppem oder Metagruppen hinzu, aber das kann ich heute noch nicht absch\u00e4tzen.<\/p>\n\n\n\n<p>Wie sieht denn dann so eine Ansible-Inventory Datei im YAML Format aus:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible@CT101-Ansible ~# more \/etc\/ansible\/hosts\n\n---\ncontainers:\n  hosts:\n    ct100-nextcloud:\n      ansible_host: fda0:d594:f020:ffff::50\n    ct101-ansible:\n      ansible_host: fda0:d594:f020:ffff::55\n\nphysicals:\n  hosts:\n    pve1:\n      ansible_host: fda0:d594:f020:ffff::30\n    bammbamm:\n      ansible_host: fda0:d594:f020:ffff:21e:6ff:fe45:135f\n\nstorage:\n  hosts:\n    simstim:\n      ansible_host: fda0:d594:f020:ffff::beaf\n\nservers:\n  children:\n    containers:\n    physicals:\n    storage:<\/code><\/pre>\n\n\n\n<p>Doch Ansible hat da noch weitere Boardmittel zu Anzeige des Inventorys, welche sp\u00e4ter bei der Variablen-Definition auch gute dienste leisten werden. Okay, zu erst stellt sich die Frage wie sieht Ansible die Datei? Daf\u00fcr kann man sich das Inventory als Liste ausgeben lassen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible@CT101-Ansible ~# ansible-inventory --list\n\n{\n    \"_meta\": {\n        \"hostvars\": {\n            \"bammbamm\": {\n                \"ansible_host\": \"fda0:d594:f020:ffff:21e:6ff:fe45:135f\"\n            },\n            \"ct100-nextcloud\": {\n                \"ansible_host\": \"fda0:d594:f020:ffff::50\"\n            },\n            \"ct101-ansible\": {\n                \"ansible_host\": \"fda0:d594:f020:ffff::55\"\n            },\n            \"pve1\": {\n                \"ansible_host\": \"fda0:d594:f020:ffff::30\"\n            },\n            \"simstim\": {\n                \"ansible_host\": \"fda0:d594:f020:ffff::beaf\"\n            }\n        }\n    },\n    \"all\": {\n        \"children\": &#091;\n            \"servers\",\n            \"ungrouped\"\n        ]\n    },\n    \"containers\": {\n        \"hosts\": &#091;\n            \"ct100-nextcloud\",\n            \"ct101-ansible\"\n        ]\n    },\n    \"physicals\": {\n        \"hosts\": &#091;\n            \"bammbamm\",\n            \"pve1\"\n        ]\n    },\n    \"servers\": {\n        \"children\": &#091;\n            \"containers\",\n            \"physicals\",\n            \"storage\"\n        ]\n    },\n    \"storage\": {\n        \"hosts\": &#091;\n            \"simstim\"\n        ]\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>In komplexeren Umgebungen wird dieser Auszug dann schnell un\u00fcbersichtlich, was die n\u00e4chste Befehlsoption f\u00fcr ansible-inventory sinvoll erscheinen l\u00e4\u00dft &#8211; n\u00e4mlich Option Graph. Wir eine logische Struktur als Graph dargestellt.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible@CT101-Ansible ~# ansible-inventory --graph\n\n@all:\n  |--@servers:\n  |  |--@containers:\n  |  |  |--ct100-nextcloud\n  |  |  |--ct101-ansible\n  |  |--@physicals:\n  |  |  |--bammbamm\n  |  |  |--pve1\n  |  |--@storage:\n  |  |  |--simstim\n  |--@ungrouped:\n<\/code><\/pre>\n\n\n\n<p>Nat\u00fcrlich kann man sich auch die Details nur einer Komponente im Inventory anzeigen lassen, das geht dan mit der Option Host &lt;xyz&gt;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible@CT101-Ansible ~# ansible-inventory --host pve1\n\n{\n    \"ansible_host\": \"fda0:d594:f020:ffff::30\"\n}<\/code><\/pre>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Verbindungskontrolle durch Modul Ping<\/mark><\/strong><\/p>\n\n\n\n<p>Dann pr\u00fcfen wir doch mal mittels Ansible Modul Ping, ob wir uns bei den Komponeten anmelden k\u00f6nnen. Das muss(!!) jetzt schief gehen, da keine Public-Keys ausgetauscht wurden und ich nicht mit Usernamen+Passw\u00f6rtnern herum hantieren will&#8230; \ud83d\ude09<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> ansible@CT101-Ansible ~# ansible -m ping servers\n\npve1 | UNREACHABLE! =&gt; {\n    \"changed\": false,\n    \"msg\": \"Failed to connect to the host via ssh: Warning: Permanently added 'fda0:d594:f020:ffff::30' (ECDSA) to the list of known hosts.\\r\\nroot@fda0:d594:f020:ffff::30: Permission denied (publickey,password).\",\n    \"unreachable\": true\n}\nct101-ansible | UNREACHABLE! =&gt; {\n    \"changed\": false,\n    \"msg\": \"Failed to connect to the host via ssh: Warning: Permanently added 'fda0:d594:f020:ffff::55' (ECDSA) to the list of known hosts.\\r\\n\\nroot@fda0:d594:f020:ffff::55: Permission denied (publickey,password).\",\n    \"unreachable\": true\n}\nbammbamm | UNREACHABLE! =&gt; {\n    \"changed\": false,\n    \"msg\": \"Failed to connect to the host via ssh: Warning: Permanently added 'fda0:d594:f020:ffff:21e:6ff:fe45:135f' (ECDSA) to the list of known hosts.\\r\\nroot@fda0:d594:f020:ffff:21e:6ff:fe45:135f: Permission denied (publickey,password).\",\n    \"unreachable\": true\n}\nct100-nextcloud | UNREACHABLE! =&gt; {\n    \"changed\": false,\n    \"msg\": \"Failed to connect to the host via ssh: Warning: Permanently added 'fda0:d594:f020:ffff::50' (ECDSA) to the list of known hosts.\\r\\n\\nroot@fda0:d594:f020:ffff::50: Permission denied (publickey,password).\",\n    \"unreachable\": true\n}\nsimstim | UNREACHABLE! =&gt; {\n    \"changed\": false,\n    \"msg\": \"Failed to connect to the host via ssh: Warning: Permanently added 'fda0:d594:f020:ffff::beaf' (RSA) to the list of known hosts.\\r\\nroot@fda0:d594:f020:ffff::beaf: Permission denied (publickey,password,keyboard-interactive).\",\n    \"unreachable\": true\n}\n<\/code><\/pre>\n\n\n\n<p>Was sehen wir im Output? Er hat alle Hosts der Metagruppe Servers und damit auch die echten Hosts in den Gruppen per SSH versucht zu erreichen und ist wegen mangelendem Publickey oder Passwort beim Versuch abgewiesen worden. Allerdings hat er in diesem Test auch gleich die Fingerprints der Server eingesammelt. Der Fingerprint der oben angelegten 5 Server l\u00e4\u00dft sich gut als Treasure Map Output der lokalen SSH Known Hosts Datei darstellen mit ssh-keygen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible@CT101-Ansible ~\/.ssh# ssh-keygen -l -v -f ~\/.ssh\/known_hosts\n\n256 SHA256:PF7+vUYuVdp0J5pTxQOOi89WA2GWbmhFOzB2z+RxjXc |1|Ho+JJ1swoyouCm0GnsyqHi57Xxc=|hbe7LQpltrAdaZmuMamMtHni37Q= (ECDSA)\n+---&#091;ECDSA 256]---+\n|         +.*.+.+.|\n|        . *oX +.E|\n|          += = oo|\n|       . o.o+ o =|\n|        S.o. * *o|\n|       . +o = = .|\n|        . .+ =   |\n|          ....o  |\n|            .oo. |\n+----&#091;SHA256]-----+\n\n256 SHA256:k14SkrnMi+NCldQvzE8OFTxf1Wx4E4uN3JmSEnzUe8E |1|QDEQ4TRydOWWQPmeevnUAQkz8gY=|OWcAxe9X8W02I3rm7gJ+SSdm5JM= (ECDSA)\n+---&#091;ECDSA 256]---+\n|     . ......o+=.|\n|    . .o+  .+.BEO|\n|   . ++o.o o.* O+|\n|    oo=ooo. . ...|\n|   .  +*S .     .|\n|  .  . oo+       |\n| .  o . .        |\n|  .. .           |\n|   ..            |\n+----&#091;SHA256]-----+\n\n256 SHA256:jlUKiFC6HhsbnE+1HtI85aqOjASzMjmcmZUdFrweINU |1|QfGQ0dLww4m5KEwDWF4UDf+ONSg=|hyzL8JMg6flQyqlBkcOwafeO8y8= (ECDSA)\n+---&#091;ECDSA 256]---+\n|..o.o.           |\n| + o E.          |\n|. o o+o.  .      |\n|... Bo=. o       |\n|+* =.B..S        |\n|++&amp; o.++         |\n|*X . o. .        |\n|=o. .            |\n|.o.o             |\n+----&#091;SHA256]-----+\n\n256 SHA256:XHIV05fJpMcCjildoQwC6ilicaRum1ofRgWCa0h99CU |1|jYtmrzfE2VFF7+06jZaE9DPSfhM=|\/kaTGBH4S0\/mOOYii5UTKjHU7i8= (ECDSA)\n+---&#091;ECDSA 256]---+\n| .oo+o E . +=oo.o|\n|..+o oo * *...++.|\n|o= .. .o.*o. o + |\n|=.+  . ..+    o  |\n|+*  .   S        |\n|= o.             |\n| o. o            |\n|.. o .           |\n|.   .            |\n+----&#091;SHA256]-----+\n\n2048 SHA256:xOC7v\/H6mli+IGS2pFVakM2VO3Kjv9SeQn67tU0DNQ8 |1|xzz4PWUgki+T6hOv0jZOwiB6\/Ac=|52e4WoWIvItfh31VfWRV2PGC6f0= (RSA)\n+---&#091;RSA 2048]----+\n|    .+....       |\n|    .ooo.        |\n|      + o.    E  |\n|     +.o=    . + |\n|    B .+So  .   .|\n|   B .....   .   |\n|  . o o++ . . o  |\n|     . B+=.o + . |\n|      . XXBo. .  |\n+----&#091;SHA256]-----+\n<\/code><\/pre>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Anlegen eines SSH Keys<\/mark><\/strong><\/p>\n\n\n\n<p>Da f\u00e4llt mir doch glatt auf, dass ich noch keinen SSH_Key f\u00fcr das Login erzeugt habe auf dem Container Ansible. Dann holen wir das mal flott nach, damit ich \u00fcberhaupt einen Schl\u00fcssel zum Austauschen habe. Hier nur als Beispiel, der echte Schl\u00fcssel ist dann zur Nutzung ein anderer. Ich kodiere gerne meinen Usernamen, das Nutzungssystem und den Zeitpunkt der Erzeugung mit in den Schl\u00fcssel, damit ich sp\u00e4ter nachvollziehen kann, woher der Stammt. \ud83d\ude42<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible@CT101-Ansible ~\/.ssh# ssh-keygen -o -a 100 -t ed25519 -C \"$(whoami)@$(uname -n)-$(date -I)\"\n\nGenerating public\/private ed25519 key pair.\nEnter file in which to save the key (~\/.ssh\/id_ed25519): \nEnter passphrase (empty for no passphrase): \nEnter same passphrase again: \nYour identification has been saved in ~\/.ssh\/id_ed25519\nYour public key has been saved in ~\/.ssh\/id_ed25519.pub\n\nThe key fingerprint is:\nSHA256:C8hq+RrXVKexX0zMakzdJKe+hDpJTNQ6sY\/XA53+fBY ansible@CT101-Ansible\nThe key's randomart image is:\n+--&#091;ED25519 256]--+\n|        ..  . o  |\n|       .. .+ *   |\n|        ++o.*..  |\n|   . . ++B.*o    |\n|    o o S+=+=    |\n|   o o o.*oo+. E |\n|  = . . =.. .+  .|\n| . +     .    o o|\n|  ...          o |\n+----&#091;SHA256]-----+\n\n\n<\/code><\/pre>\n\n\n\n<p>Wenn dieser Publickey dann auf einem anderen System liegt kann man hinein sehen und zumindest nachvollziehen, wer ihn auf welchem System wann erzeugt hat. Das geht dann Beispielsweise so.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible@CT100-Nextcloud ~\/.ssh# ssh-keygen -l -v -f ~\/.ssh\/authorized_keys \nSHA256:C8hq+RrXVKexX0zMakzdJKe+hDpJTNQ6sY\/XA53+fBY root@CT101-Ansible-2024-03-21\n\n+--&#091;ED25519 256]--+\n|        ..  . o  |\n|       .. .+ *   |\n|        ++o.*..  |\n|   . . ++B.*o    |\n|    o o S+=+=    |\n|   o o o.*oo+. E |\n|  = . . =.. .+  .|\n| . +     .    o o|\n|  ...          o |ansible@CT101-Ansible ~# \n+----&#091;SHA256]-----+\n\n<\/code><\/pre>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Verteilen des SSH-Keys<\/mark><\/strong><\/p>\n\n\n\n<p>Der Publickey muss nun noch auf die Systeme verteilt werden. Ich hatte dummerweise vorher nicht gepr\u00fcft, ab alle Systeme ED25519 kompatibel sind.. \ud83d\ude41<\/p>\n\n\n\n<p>Als Beispiel nehme ich hier zum zeigen nur einen Server, was zum Verstehen des Ablaufs allerdings ausreichend sein sollte. Ich pushe also den Publickey, logge mich direkt im Anschlu\u00df mittels Publickey auf diesem Server in ssh ein und lasse mir die \/root\/.ssh\/authorized_keys anzeigen.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pushen:\n------&gt;\nansible@CT101-Ansible ~\/.ssh# ssh-copy-id -i ~\/.ssh\/id_ed25519.pub root@fda0:d594:f020:ffff::50\n\/usr\/bin\/ssh-copy-id: INFO: Source of key(s) to be installed: \"\/root\/.ssh\/id_ed25519.pub\"\n\/usr\/bin\/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed\n\/usr\/bin\/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys\n\nroot@fda0:d594:f020:ffff::50's password: \n\nNumber of key(s) added: 1\n\nNow try logging into the machine, with:   \"ssh 'root@fda0:d594:f020:ffff::50'\"\nand check to make sure that only the key(s) you wanted were added.\n \n\n\n\nssh login mit publickey:\n-----------------------&gt;\nansible@CT101-Ansible ~\/.ssh# ssh fda0:d594:f020:ffff::50\n\nWelcome to Ct100-nextcloud, TurnKey GNU\/Linux 17.2 (Debian 11\/Bullseye)\n\n  System information for Thu Mar 21 19:14:30 2024 (UTC+0000)\n  \n    System load:  0.04               Memory usage:  5.1%\n    Processes:    43                 Swap usage:    0.0%\n    Usage of \/:   5.0% of 294.23GB   IP address for eth0: 192.168.2.50\n\nLinux CT100-Nextcloud 6.5.13-1-pve #1 SMP PREEMPT_DYNAMIC PMX 6.5.13-1 (2024-02-05T13:50Z) x86_64\nLast login: Wed Mar 20 17:01:47 2024\n\n\n\nauthorized_keys:\n---------------&gt;\nroot@CT100-Nextcloud ~# cat .ssh\/authorized_keys \nssh-ed25519 xOC7v\/H6mli+IGS2pFVakM2VO3Kjv9SeQn67tU0DNQ8\n<\/code><\/pre>\n\n\n\n<p><strong><mark class=\"has-inline-color has-vivid-cyan-blue-color\">Erneute Verbindungskontrolle durch Modul Ping<\/mark><\/strong><\/p>\n\n\n\n<p>Auf allen Systemen ist nun der Publickey verteilt. Wollen wir doch noch einmal pr\u00fcfen, ob wir dann jetzt zu den Komponenten durch Ansible sprechen k\u00f6nnen. Also wieder das Modul Ping nutzen und den Output analysieren.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ansible@CT101-Ansible ~# ansible -m ping servers\n\npve1 | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python3\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\nct100-nextcloud | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python3\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\nbammbamm | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python3\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\nct101-ansible | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python3\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\nsimstim | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\n\n<\/code><\/pre>\n\n\n\n<p>Alle Systeme antworten und sind erreichbar. Damit ist das Etappenziel f\u00fcr Ansible mit dem Inventory-Setup erreicht.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Im letzten Artikel habe ich den Ansible und Semaphore LXC Container aufgesetzt. Zeit diesen so zu konfigurieren, dass wir zuerst einmal mit dem Ansible auf andere Komponenten zugreifen k\u00f6nnen und dann auch die gew\u00fcnschten&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":2325,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,112,10,121],"tags":[55,117,119,113],"class_list":["post-2323","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-microservices","category-netzwerken","category-proxmox","tag-ansible","tag-lxc","tag-lxc-container","tag-proxmox"],"_links":{"self":[{"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2323","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2323"}],"version-history":[{"count":42,"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2323\/revisions"}],"predecessor-version":[{"id":2418,"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=\/wp\/v2\/posts\/2323\/revisions\/2418"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=\/wp\/v2\/media\/2325"}],"wp:attachment":[{"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2323"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.fotoandnet.de\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}