Hoe installeer je Ansible op CentOS 8
In dit artikel zetten we de nodige stappen uiteen om Ansible op CentOS 8 te installeren. Voordat je doorgaat met deze tutorial, controleer of je ingelogd bent als gebruiker met sudo-rechten. Alle commando’s dienen uitgevoerd te worden als een non-root user.
Ansible is een gratis open source configuratie en automation software tool voor UNIX-besturingssystemen. Het is geschreven in Python en vergelijkbaar met Chef of Puppet. Het wezenlijke verschil en voordeel van Ansible is dat we geen agent op de nodes hoeven te installeren. De software maakt gebruik van de SSH om te communiceren met verschillende nodes.
CentOS 8 Basis
De basis voor de onderstaande cases is een minimal install van CentOS 8.2. Voer onderstaande commando’s in voor EPEL repository en update.
sudo dnf update -y
Stap 1. Installeer ansible
sudo dnf install ansible -y
ansible –version
>> ansible 2.9.14
>> config file = /etc/ansible/ansible.cfg
>> configured module search path = [‘/home/<USER>/.ansible/plugins/modules’, ‘/usr/share/ansible/plugins/modules’]
>> ansible python module location = /usr/lib/python3.6/site-packages/ansible
>> executable location = /usr/bin/ansible
>> python version = 3.6.8 (default, Apr 16 2020, 01:36:27) [GCC 8.3.1 20191121 (Red Hat 8.3.1-5)]
Stap 2. Genereer SSH keys voor root user
sudo su –
ssh-keygen -t rsa -b 4096
bevestig de default door ENTER te drukken
>> Generating public/private rsa key pair.
>> Enter file in which to save the key (/root/.ssh/id_rsa):
>> Created directory ‘/root/.ssh’.
>> 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:ZR4GSF6xk7JHCPds8hmUiuAqcQIUizbXSfwQn4prSh0 root@<hostname>
stap 3. Achterhaal het IP adres van je server
ping <hostname>
>> 192.168.2.10 <=== voorbeeld!!
Stap 4. Kopieer de SSH key voor de root user
ssh-copy-id root@192.168.2.10
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: “/root/.ssh/id_rsa.pub”
The authenticity of host ‘192.168.2.10 (192.168.2.10)’ can’t be established.
ECDSA key fingerprint is SHA256:nFTJSLDRSFQoyvGx8PCwoVQrWhDU8Mb9cPRjin/D61E.
Are you sure you want to continue connecting (yes/no/[fingerprint])? 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
root@192.168.2.10’s password:
Number of key(s) added: 1
Now try logging into the machine, with: “ssh ‘root@192.168.2.10′”
and check to make sure that only the key(s) you wanted were added.
Stap 5. Configureer dezelfde server als client
vi /etc/ansible/hosts
shift-g
<esc>i
[testservers]
192.168.2.10
Stap 6. Controleer de client via een ping
ansible -m ping ’testservers’
>> 192.168.2.10 | SUCCESS => {
>> “ansible_facts”: {
>> “discovered_interpreter_python”: “/usr/libexec/platform-python”
>> },
>> “changed”: false,
>> “ping”: “pong”
>> }
Stap 7. Controleer de uptime van de client
ansible -m command -a “uptime” ’testservers’
>> 192.168.2.10 | CHANGED | rc=0 >>
>> 14:56:02 up 8 days, 4:54, 2 users, load average: 0.04, 0.07, 0.11
IT-traineeship
Gefeliciteerd, je hebt Ansible geïnstalleerd op Ubuntu. Mocht je jezelf nog verder willen ontwikkelen met bijvoorbeeld configuration management tools of container technologie zoals Docker en Kubernetes en willen weten hoe je dit kan implementeren voor een organisatie in de Cloud? Dan is het Axxius IT-traineeship precies wat je zoekt. Neem contact met ons op zodat wij een eerste gesprek kunnen inplannen en de mogelijkheden met jou kunnen bespreken.