Préparer un serveur client Ansible

cyril
Site Admin
Messages : 47
Inscription : 29 mars 2021, 21:50

Préparer un serveur client Ansible

Message par cyril »

1) Créer la clé ssh

Code : Tout sélectionner

ssh-keygen

Code : Tout sélectionner

Generating public/private rsa key pair.

Enter file in which to save the key (/home/geekflare/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/geekflare/.ssh/id_rsa.

Your public key has been saved in /home/geekflare/.ssh/id_rsa.pub.

The key fingerprint is:

SHA256:3XDm62tzJegGm8oAmFYCyeFZovJOuU42zNgyn9GzH30 geekflare@geekflare

The key's randomart image is:

+---[RSA 2048]----+

|o+..             |

|+o+              |

|oo. .     . o    |

|.. *     . *     |

|  B .   S . o.   |

| O o . .  . ... .|

|+ @ o o . E=.  o |

| B + o + .o.= .  |

|  + ... o. oo+   |

+----[SHA256]-----+
2) Créer le user ansible sur le serveur client

Code : Tout sélectionner

sudo adduser --shell /bin/bash --gecos "" ansible
3) Copier la clé ssh

Code : Tout sélectionner

ssh-copy-id ansible@serveurhost
4) Ajouter l'utilisateur ansible dans les sudores du serveur client

Code : Tout sélectionner

sudo visudo

Code : Tout sélectionner

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
ansible ALL=(ALL) NOPASSWD:ALL
# See sudoers(5) for more information on "@include" directives:

@includedir /etc/sudoers.d
5) Sécuriser l'utilisateur ansible pour ne pas pouvoir l'utiliser sur le serveur

Code : Tout sélectionner

sudo usermod -L ansible
Répondre