GNU/Linux >> LINUX-Kenntnisse >  >> Ubuntu

So installieren Sie Ansible unter Ubuntu 18.04

In diesem Artikel haben wir die notwendigen Schritte zur Installation und Konfiguration von Ansible auf Ubuntu 18.04 LTS erklärt. Bevor Sie mit diesem Tutorial fortfahren, vergewissern Sie sich, dass Sie als Benutzer mit sudo-Berechtigungen angemeldet sind. Alle Befehle in diesem Tutorial sollten als Nicht-Root-Benutzer ausgeführt werden.

Ansible ist ein kostenloses und quelloffenes Konfigurations- und Automatisierungstool für UNIX-ähnliche Betriebssysteme. Es ist in Python geschrieben und ähnelt Chef oder Puppet, aber es gibt einen Unterschied und Vorteil von Ansible ist, dass wir keinen Agenten auf den Knoten installieren müssen. Es verwendet SSH für die Kommunikation mit seinen Knoten.

In diesem Artikel zeigen wir, wie Ansible in Ubuntu installiert und konfiguriert wird, und versuchen, die beiden Knoten zu verwalten:

  • Ansible-Server – ansible.idroot.us ( 192.168.13.33 )
  • Ansible-Client – ​​192.168.100.120

Installieren Sie Ansible auf Ubuntu

Schritt 1. Bevor Sie mit der Installation eines Pakets auf Ihrem Ubuntu-Server beginnen, empfehlen wir immer, sicherzustellen, dass alle Systempakete aktualisiert sind.

sudo apt update
sudo apt upgrade

Schritt 2. Installieren Sie Ansible auf Ubuntu.

Wir müssen zuerst das ansible Repo aktivieren. Installieren Sie das Repo mit dem folgenden Befehl:

sudo apt-add-repository ppa:ansible/ansible

Nachdem Sie das Ansible-Repository hinzugefügt haben, führen Sie die folgenden Befehle zur Installation aus:

sudo apt update
sudo apt install ansible

Nach erfolgreicher Installation von Ansible können Sie die installierte Version von Ansible überprüfen, indem Sie Folgendes ausführen:

sudo ansible --version

Schritt 3. Richten Sie eine passwortlose SSH-Konfiguration zwischen dem Ansible-Server und dem Ansible-Client ein.

Wir müssen SSH-Schlüssel auf dem Ansible-Server generieren und diesen Schlüssel in den öffentlichen Schlüssel auf dem Ansible-Client kopieren:

[example@unixlinux.online ~]# ssh-keygen -t rsa -b 4096 -C "example@unixlinux.online"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:rqAwbwQ8/meilanamaria4D2V0fQ49amw2WKbYIA example@unixlinux.online
The key's randomart image is:
+---[RSA 4096]----+
| .oo.+o |
| . =.=.. . |
|. E o + X . o |
|.o. + + = X . |
| .o. + oSX + |
| .. o.+ = |
|o. o oo.o |
| +.. +oo |
| .o ... |
+----[SHA256]-----+
[example@unixlinux.online ~]#

Wir können den Befehl ssh-copy-id verwenden, um den öffentlichen Schlüssel vom Ansible-Server auf Ansible-Clients zu kopieren:

[example@unixlinux.online ~]# ssh-copy-id example@unixlinux.online
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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
example@unixlinux.online's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'example@unixlinux.online'"
and check to make sure that only the key(s) you wanted were added.

[example@unixlinux.online ~]#
[example@unixlinux.online ~]# ssh-copy-id example@unixlinux.online
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.43.131 (192.168.43.131)' can't be established.
ECDSA key fingerprint is SHA256:OuHrnRxppengenkimpoi5Z+1tOWOF8eYZ5Le5MNwUQ.
ECDSA key fingerprint is MD5:78:1c:a5:72:bb:25:fa:c7:67:39:fc:91:b9:fb:b6:20.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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
example@unixlinux.online's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'example@unixlinux.online'"
and check to make sure that only the key(s) you wanted were added.

[example@unixlinux.online ~]#
===============================
[example@unixlinux.online ~]# ssh example@unixlinux.online
Last login: Thu Sep 19 16:00:57 2019 from bezafari-c1
[example@unixlinux.online ~]# exit
logout
Connection to 192.168.100.120 closed.
[example@unixlinux.online ~]#

Wir müssen überprüfen, ob unser Ansible-Server und Ansible-Clients funktionieren, Passwort weniger oder nicht? Wir können wie folgt überprüfen:

[example@unixlinux.online ~]# ssh example@unixlinux.online
Last login: Thu Jan 17 17:00:57 2019 from bezafari-c1
[example@unixlinux.online ~]# exit
logout
Connection to 192.168.100.120 closed.
[example@unixlinux.online ~]#

Schritt 4. Konfiguration des Ansible-Servers zur Verwaltung des Ansible-Clients.

Sie können unseren Ansible-Server und Ansible-Client mithilfe der Ansible-Server-Hostdatei inventarisieren. Die Host-Datei befindet sich in diesem Pfad auf dem Ansible-Server /etc/ansible/host:

[example@unixlinux.online ~]# nano /etc/ansible/hosts
[test-servers]
192.168.13.33
192.168.100.120

Schritt 5. Ansible-Client vom Ansible-Server verwalten.

Überprüfen Sie die Konnektivität von „Testservern“ oder Ansible-Clients mit Ping:

[example@unixlinux.online ~]# ansible -m ping 'test-servers'
192.168.13.33 | SUCCESS => {
"changed": false,
"ping": "pong"
}
192.168.100.120 | SUCCESS => {
"changed": false,
"ping": "pong"
}
[example@unixlinux.online ~]#

Wir können die Verfügbarkeit unseres Ansible-Clients vom Ansible-Server überprüfen:

[example@unixlinux.online ~]# ansible -m command -a "uptime" 'test-servers'
192.168.100.120 | CHANGED | rc=0 >>
16:17:35 up 20 min, 3 users, load average: 0.09, 0.16, 0.29

192.168.13.33 | CHANGED | rc=0 >>
16:17:35 up 22 min, 4 users, load average: 0.18, 0.29, 0.55

[example@unixlinux.online ~]#

Umleitung der Ausgabe des Befehls in eine Datei. Wie unten:

[example@unixlinux.online ~]# ansible -m command -a "df -Th" 'test-servers' > /tmp/command-output.txt
[example@unixlinux.online ~]# cat /tmp/command-output.txt
192.168.13.33 | CHANGED | rc=0 >>
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 13G 5.0G 8.0G 39% /
devtmpfs devtmpfs 482M 0 482M 0% /dev
tmpfs tmpfs 497M 212K 497M 1% /dev/shm
tmpfs tmpfs 497M 7.1M 490M 2% /run
tmpfs tmpfs 497M 0 497M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 158M 340M 32% /boot
tmpfs tmpfs 100M 16K 100M 1% /run/user/0
192.168.100.120 | CHANGED | rc=0 >>
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 13G 3.9G 9.1G 30% /
devtmpfs devtmpfs 906M 0 906M 0% /dev
tmpfs tmpfs 921M 84K 920M 1% /dev/shm
tmpfs tmpfs 921M 8.7M 912M 1% /run
tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 157M 341M 32% /boot
tmpfs tmpfs 185M 20K 184M 1% /run/user/42
tmpfs tmpfs 185M 0 185M 0% /run/user/0
[example@unixlinux.online ~]#

Das ist alles, was Sie tun müssen, um Ansible unter Ubuntu 18.04 zu installieren. Ich hoffe, Sie finden diesen schnellen Tipp hilfreich. Wenn Sie Fragen oder Anregungen haben, können Sie unten einen Kommentar hinterlassen.


Ubuntu
  1. So installieren Sie R unter Ubuntu 20.04

  2. So installieren Sie Go unter Ubuntu 18.04

  3. So installieren Sie Ansible auf Ubuntu Server 21.04

  4. So installieren Sie Ansible unter Ubuntu 18.04 LTS

  5. So installieren Sie R unter Ubuntu 16.04

So installieren Sie Ansible unter Ubuntu 20.04

So installieren Sie Ansible unter Ubuntu 16.04 (Xenial)

So installieren Sie OpenVPN unter Ubuntu 16.04 LTS

So installieren Sie Go in Ubuntu 20.04

So installieren Sie Go unter Ubuntu 22.04

So installieren Sie Ansible Server unter Ubuntu 18.04