Giter Site home page Giter Site logo

ansible-examples's Introduction

Installation du bac a sable ansible-examples

Pre-requis pour Centos 7

sudo yum -y update   # update all packages 
sudo yum -y install git wget   # install git and wget 
sudo yum -y install epel-release  # added extra packages
sudo yum -y install htop iotop iftop  # added monitoring tools
sudo yum -y install python3 

installation de Docker

Installation de la derniere version de Docker sous Centos

L'installation de Docker necessite certains packages.

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

Ensuite nous devons mettre en place le lien vers le repository Docker.

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

Installer la derniere version de Docker et de ses packages client et containerd.io

 sudo yum install -y docker-ce docker-ce-cli containerd.io

Lancer le daemon Docker

sudo systemctl start docker

Placer un lien symbolique pour que le daemon Docker demarre automatiquement meme si le host est reboote.

sudo systemctl enable docker
sudo usermod -aG docker centos  # fermer votre shell pour les chargements soient appliques

Mise en place des containers et du fichier inventory

Demarrer des containers pour simuler plusieurs machines.

docker run -d --name target1 systemdevformations/ubuntu_ssh:v2  
docker run -d --name target2 systemdevformations/centos_ssh:v5 
docker run -d --name target3 --env ROOT_PASSWORD=Passw0rd systemdevformations/alpine-ssh:v1   

Retrouver le nom des containers
Faire un docker ps | grep systemdevformation

CONTAINER ID        IMAGE                               COMMAND                  CREATED             STATUS                    PORTS                  NAMES
f5034036dc56        systemdevformations/alpine-ssh:v1   "/entrypoint.sh"         11 hours ago        Up 11 hours               22/tcp                 target3
c714f0b92509        systemdevformations/centos_ssh:v5   "/usr/bin/supervisor…"   23 hours ago        Up 23 hours (unhealthy)   22/tcp                 target2
6051c68c1712        systemdevformations/ubuntu_ssh:v2   "/usr/sbin/sshd -D"      23 hours ago        Up 23 hours               22/tcp                 target1              target1  

et retrouver l'adresse IP des containers, et notez les

docker network inspect bridge

en fonction de l'adresses IP fournie pendant le cours
modifier egalement la VM ansible-remote

Dans votre home directory, faire
ssh-keygen -t rsa -b 4096 -C "votre adresse mail"
Valider les parametres par defaut
sans passphrase
Et
ssh-copy-id centos@<remote_id_address>

Installation de VirtualEnv Python et faire des Tests avec les Ad-Hoc commandes

Dans votre home directory faire un git clone de https://github.com/<votre_repo>/ansible-examples.git

Dans votre projet ansible-examples, faire

cd ansible-examples 
python3 -m venv venv

cela installe le systeme virtualenv Python dans la directory venv
Faire
source venv/bin/activate
Votre prompt change
(venv) [centos@ansible-oxiane-controller-2 ~]$
Faire
pip3 install wheel
installe le package wheel qui gere les permission pour installer les packages Pip
et pip3 install ansible

Vous devez egalement installer le package sshpass
pour utiliser ssh avec un password, c'est-a-dire sans une cle ssh propagee.
sudo apt-get -y install sshpass
avec centos
sudo yum -y install sshpass

changer le ficher inventory avec les nouvelles adresses IP

et faire la commande Ansible Ad-Hoc pour verifier si votre fichier inventory est correct.
ansible all -m ping -i inventory Faire ensuite les Ad-Hoc commandes suivantes:

ansible centos -m yum -a "name=elinks state=latest" -i inventory
ansible centosremote -m yum -a "name=elinks state=latest" -i inventory
ansible centosremote -b -m yum -a "name=elinks state=latest" -i inventory
ansible all --list-hosts -i inventory
ansible all -m setup -a "filter=ansible_default_ipv4"  -i inventory
ansible all -m setup -a "filter=ansible_distribution"  -i inventory 
ansible all -m setup -a "filter=ansible_distribution_version"  -i inventory 
ansible all -m command -a "df -h" -i inventory
# -- ansible centos -b -m yum -a "name=* state=latest" -f 10  -i inventory  # default = 5
ansible centos -m file -a "dest=/home/centos/testfile state=touch" -i inventory 

Presentation des groupes

Mettre a jour le ficher inventory_children sans en modifier la structure

Premier script YAML

Dans la directory ansible-examples editez le fichier ansible_ping.yml, et etudiez le code.

Premieres commandes ansible-playbook

ansible-playbook  -i inventory_children ansible_ping.yml  --limit centosdocker
ansible-playbook  -i inventory_children ansible_ping.yml  --limit centos

ansible-examples's People

Contributors

dockerlite avatar numerica-ansible avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.