Formation DevOps | Formation Terraform : 12- Premier pas avec Terraform :remote exec
Terraform : remote_exec
- Connection sur le remote server ensuite installation de nginx:
Les provisionneurs peuvent être utilisés pour modéliser des actions spécifiques sur la machine locale ou sur une machine distante afin de préparer des serveurs ou d’autres objets d’infrastructure pour le service.
variable “ssh_host” {}
variable “ssh_user” {}
variable “ssh_key” {}
resource “null_resource” “ssh_target” {
connection {
type = “ssh”
user = var.ssh_user
host = var.ssh_host
private_key = file(var.ssh_key)}
provisioner “remote-exec” {
inline = [
“sudo apt update -qq >/dev/null”,
“sudo apt install -qq -y nginx >/dev/null”
]
}
}
- Connection sur le remote server ensuite installation de nginx:
Terraform.tfvars
ssh_host = “35.181.154.86”
ssh_user = “ubuntu”
ssh_key = “/home/ubuntu/.ssh/id_rsa”
Remote-server
`
- Connection sur le remote server ensuite installation de nginx:
variable “ssh_host” {}
variable “ssh_user” {}
variable “ssh_key” {}
resource “null_resource” “ssh_target” {
connection {
type = “ssh”
user = var.ssh_user
host = var.ssh_host
private_key = file(var.ssh_key)
}
provisioner “remote-exec” {
inline = [
“sudo apt update -qq >/dev/null”,
“sudo apt install -qq -y nginx >/dev/null”
]
}
provisioner “file” {
source = “nginx.conf”
destination = “/tmp/default”
}
provisioner “remote-exec” {
inline = [
“sudo cp -a /tmp/default /etc/nginx/sites-available/default”,
“sudo systemctl restart nginx”
]
}
provisioner “local-exec” {
command = “curl ${var.ssh_host}:6666”
}
}
output “host” {
value = var.ssh_host
}
output “user” {
value = var.ssh_user
}
output “key” {
value = var.ssh_key
}
/!\Copy de file vers remote server sans sudo
/!\sudo est utilisé dans remote-exec
Workshop : mise en place d’un serveur apache avec une page web personnalisée.
1.Installation de docker:
variable “ssh_host” {}
variable “ssh_user” {}
variable “ssh_key” {}
resource “null_resource” “ssh_target” {
connection {
type = “ssh”
user = var.ssh_user
host = var.ssh_host
private_key = file(var.ssh_key)
}
provisioner “remote-exec” {
inline = [
“sudo apt update -qq >/dev/null”,
“curl -fsSL https://get.docker.com -o get-docker.sh”,
“sudo chmod 755 get-docker.sh”,
“sudo ./get-docker.sh >/dev/null”
]
}
provisioner “file” {
source = “startup-options.conf”
destination = “/tmp/startup-options.conf”
}
provisioner “remote-exec” {
inline = [
“sudo mkdir -p /etc/systemd/system/docker.service.d/”,
“sudo cp /tmp/startup-options.conf /etc/systemd/system/docker.service.d/startup_options.conf”,
“sudo systemctl daemon-reload”,
“sudo systemctl restart docker”,
“sudo usermod -aG docker user-client”
]
}
}
output “host” {
value = var.ssh_host
}
output “user” {
value = var.ssh_user
}
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
ssh_host = “35.181.154.86”
ssh_user = “ubuntu”
ssh_key = “/home/ubuntu/.ssh/id_rsa”
Terraform.tfvars
Startup-options.conf
Main.tf
Après Remote Server
Resultat
Avant Remote Server
1. Nous contactez
- Description: Besoin de Formation et des Solutions cloud complètes pour vos applications
- Links:
2. Infra as a Service
- Description: Infrastructure cloud évolutive et sécurisée
- Links:
3. Projets Développeurs
- Description: Découvrez des opportunités passionnantes pour les développeurs
- Links:
4. Développeurs
- Description: Rejoignez notre communauté de développeurs
- Links:
5. Formations Complètes
- Description: Accédez à des formations professionnelles de haute qualité
- Links:
6. Marketplace
- Description: Découvrez notre place de marché de services
- Links:
7. Blogs
- Description: Découvrez nos blogs
- Links:
- comment creer une application mobile ?
- Comment monitorer un site web ?
- Command Checkout in git ?
- Comment git checkout to commit ?
- supprimer une branche git
- dockercoin
- kubernetes c est quoi
- architecture kubernetes
- Installer Gitlab Runner ?
- .gitlab-ci.yml exemples
- CI/CD
- svelte 5 vs solid
- svelte vs lit
- solidjs vs qwik
- alpine vs vue
- Plateform Freelance 2025
- Creation d’un site Web gratuitement
This website is powered by ItGalaxy.io