Aller au contenu

Gestion des instances dans Heat#


Création d'instances via Heat#

  • Utilisation de la ressource OS::Nova::Server pour définir une instance
  • Spécification des propriétés essentielles : image, flavor, key_name
heat_template_version: 2018-03-02

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      image: "cirros-0.3.5-x86_64-disk"
      flavor: "m1.tiny"
      key_name: "my_key"

📘 OpenStack Documentation: Software configuration


Configuration et personnalisation des instances#

  • Utilisation de user_data pour exécuter des scripts lors du lancement de l'instance
  • Utilisation des métadonnées pour définir des valeurs personnalisées
  • Passage de paramètres via Heat pour personnaliser l'instance lors de la création

User data#

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      image: "Ubuntu 20.04"
      flavor: "m1.small"
      key_name: "my_keypair"
      user_data: |
        #!/bin/bash
        apt-get update
        apt-get install -y apache2

Cloud init#

cloud-config
package_upgrade: true
packages:
  - apache2
write_files:
  - path: /var/www/html/index.html
    content: |
      <html>
        <head>
          <title>Welcome to my website!</title>
        </head>
        <body>
          <h1>Hello, World!</h1>
        </body>
      </html>
runcmd:
  - systemctl enable apache2
  - systemctl start apache2

Meta données#

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      image: "Ubuntu 20.04"
      flavor: "m1.small"
      key_name: "my_keypair"
      metadata:
        environment: "production"
        app_name: "my_app"

Paramètres#

parameters:
  instance_name:
    type: string
    description: Name of the instance

resources:
  my_instance:
    type: OS::Nova::Server
    properties:
      name: {get_param: instance_name}
      image: "Ubuntu 20.04"
      flavor: "m1.small"
      key_name: "my_keypair"
openstack stack create -t my_template.yaml --parameter "instance_name=my_custom_instance" my_stack