miroir de
https://github.com/PAPAMICA/Wiki-Tech.io.git
synchronisé 2024-07-05 09:30:22 +02:00
docs: create Configuration/Ansible/CLI
Cette révision appartient à :
Parent
73e1fd2d0a
révision
ff78743405
70
Configuration/Ansible/CLI.md
Fichier normal
70
Configuration/Ansible/CLI.md
Fichier normal
|
@ -0,0 +1,70 @@
|
||||||
|
---
|
||||||
|
title: Ansible - CLI
|
||||||
|
description: Comprendre et utiliser les commandes Ansibles
|
||||||
|
published: true
|
||||||
|
date: 2021-07-09T07:37:09.124Z
|
||||||
|
tags: commande, ansible, configuration
|
||||||
|
editor: markdown
|
||||||
|
dateCreated: 2021-07-09T07:37:09.124Z
|
||||||
|
---
|
||||||
|
|
||||||
|
# La commande ansible
|
||||||
|
|
||||||
|
<div class="video-responsive">
|
||||||
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/JPohVKUEnbs" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
## Informations
|
||||||
|
- peu utilisé (en proportion) au profit de ansible-playbook
|
||||||
|
- permettre du test (ping, inventaire)
|
||||||
|
- permet de jouer des tâches
|
||||||
|
- beaucoup d'options similaires à la commande ansible-playbook
|
||||||
|
|
||||||
|
## Principales options à connaître
|
||||||
|
* `-u` : user distant utilisé
|
||||||
|
* `-b` : passer les commandes en élévation de privilèges (sudo)
|
||||||
|
* `-k` ou `--ask-pass` > password SSH
|
||||||
|
* `-K` ou `--ask-become-pass` > password pour élévation privilèges
|
||||||
|
* `-C` ou `--check` : faire un dry run
|
||||||
|
* `-D` ou `--diff` : avoir un output de la diff
|
||||||
|
* `--key-file` : lien direct vers la clef privée
|
||||||
|
* `-e` ou `--extra-vars` : définir des variables
|
||||||
|
* `--ask-vault-pass` : déchiffrer un secret vault
|
||||||
|
* `--vault-password-file` : fichier pour déchiffrer
|
||||||
|
* `-f x` ou `--forks` : paralléliser
|
||||||
|
* `-vvv` : verbose
|
||||||
|
|
||||||
|
## Commandes utiles
|
||||||
|
Test de connexions
|
||||||
|
```bash
|
||||||
|
ansible -i "node2," all -u vagrant -m ping
|
||||||
|
```
|
||||||
|
Définir des paramètres ssh
|
||||||
|
```bash
|
||||||
|
ansible -i "node2," all -u vagrant -k --ssh-extra-args="-o 'PreferredAuthentications=password'" -m ping
|
||||||
|
```
|
||||||
|
|
||||||
|
sshpass pour passer un password
|
||||||
|
```bash
|
||||||
|
sshpass -p 'vagrant' ansible -i "node2," all -u vagrant -k --ssh-extra-args="-o 'PreferredAuthentications=password'" -m ping
|
||||||
|
```
|
||||||
|
|
||||||
|
Affichage oneline
|
||||||
|
```bash
|
||||||
|
ansible -i "node2," all -u vagrant -m ping --one-line
|
||||||
|
```
|
||||||
|
|
||||||
|
Module command
|
||||||
|
```bash
|
||||||
|
ansible -i "node2," all -u vagrant -m command -a uptime
|
||||||
|
```
|
||||||
|
|
||||||
|
Passage d'une variable
|
||||||
|
```bash
|
||||||
|
ansible -i "node2," all -b -e "var1=xavki" -m debug -a 'msg={{ var1 }}'
|
||||||
|
```
|
||||||
|
|
||||||
|
# Astuces avec les modules
|
||||||
|
<div class="video-responsive">
|
||||||
|
<iframe width="560" height="315" src="https://www.youtube.com/embed/blOKHSEs6IY" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
|
||||||
|
</div>
|
Chargement…
Référencer dans un nouveau ticket