Formation DevOps | Formation Terraform : 12- Premier pas avec Terraform :remote exec

www.itgalaxy.io

Terraform : remote_exec

  1. 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”
]
}
}

  1. 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
`

  1. 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


2. Infra as a Service

  • Description: Infrastructure cloud évolutive et sécurisée
  • Links:

3. Projets Développeurs


4. Développeurs


5. Formations Complètes


6. Marketplace

7. Blogs


This website is powered by ItGalaxy.io