Stellen Sie Ihre Instanzen mit Ansible bereit

Aus De Ikoula wiki
Jump to navigation Jump to search

ro:Implementarea instanțelor cu Ansible ru:Развертывание ваших экземпляров с помощью Ansible pl:Wdrażaj instancje za pomocą Ansible ja:Ansibleによるインスタンスのデプロイ zh:用Ansible部署你的实例 fr:Deployer vos instances avec Ansible
Dieser Artikel wurde maschinell übersetzt. Sie können den Artikel Quelle hier ansehen.

nl:Implementeer uw instanties met Ansible it:Distribuire le tue istanze con Ansible pt:Implante as suas instâncias com Ansible es:Despliegue de sus instancias con Ansible en:Deploy your instances with Ansible

Beschreibung

Wir werden sehen, wie man IKOULA One Cloud-Instanzen schnell über das Ansible-Tool bereitstellt

Zunächst müssen Sie Ansible installieren (https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) dann das Modul "cs_instance" (kann über "pip install cs" installiert werden). https://docs.ansible.com/ansible/2.6/modules/cs_instance_module.html) die es Ihnen ermöglicht, die Cloud Ikoula One API zu nutzen, wenn Sie dies noch nicht getan haben und ein Cloud IKOULA One-Konto besitzen.

Ansible ist für die meisten GNU/Linux-Distributionen und MacOS verfügbar, kann aber auch über Cygwin z.B. unter Microsoft Windows verwendet werden.


Bereitstellung einer Instanz mit einem einzigen Befehl mit Ansible

Sie müssen zunächst die Konfigurationsdatei ".cloudstack.ini" des Moduls "cs_instance" von Ansible erstellen und ausfüllen/anpassen:

[CloudIkoulaOne]
endpoint = https://cloudstack.ikoula.com/client/api
key = <clé API de votre utilisateur/compte Cloud IKOULA One>
secret = <clé privée de votre utilisateur/compte Cloud IKOULA One>
timeout = 30

Dann müssen Sie nur noch diesen Befehl ausführen und die Werte der Parameter (Name Ihrer Instanz, Name des Netzwerks usw.) und die Parameter selbst (z. B. ob Sie ein SSH-Schlüsselpaar verwenden müssen/wollen oder nicht) entsprechend anpassen:

ansible -i "localhost," -c local all -m cs_instance -a "name=<Nom de la VM> display_name=<Nom de la VM>  state=present template=< Nom entre simples quotes ou ID du template voulu> api_region=CloudIkoulaOne zone=<Nom de la zone voulu> service_offering=< Nom de l’offre de calcul voulu > networks=<Nom du réseau existant voulu> ssh_key=<Nom de la paire de clés ssh CIO existante>"

wobei "<Nom de l’offre de calcul voulu >" die Wahl von ist:

"t1.pico" (1/2 Core CPU with 512MB RAM and 100Mbps NIC)
"t1.micro" (1 Core CPU with 1GB RAM and 100Mbps NIC)
"m1.small" (1 Core CPU with 1.7GB RAM and 100Mbps NIC)
"m1.medium" (2 Cores CPU with 3.8GB RAM and 100Mbps NIC)
"m1.large" (4 Cores CPU with 7.6GB RAM and 100Mbps NIC)
"m1.extralarge" (8 Cores CPU with 15.3GB RAM and 100Mbps NIC)

Hier ist ein Beispiel und das Ergebnis der Ausführung:

$ ansible -i "localhost," -c local all -m cs_instance -a "name=Debian9advz1 display_name=Debian9adv1 state=present template='Debian 9 - Minimal - 64bits' api_region=CloudIkoulaOne zone=EU-FR-IKDC1-Z1-ADV service_offering=t1.micro networks=My-Network-Z1 ssh_key=MY_SSHKEY"
localhost | SUCCESS => {
    "account": "ikoula",
    "affinity_groups": [],
    "changed": true,
    "created": "2018-09-12T10:05:00+0200",
    "default_ip": "10.1.1.176",
    "display_name": "Debian9adv1",
    "domain": "ROOT",
    "hypervisor": "XenServer",
    "id": "3c60acc9-1480-48bc-ab78-934f0e607d6c",
    "instance_name": "i-1079-67026-VM",
    "name": "Debian9advz1",
    "password": "KYqrT3h28qOs",
    "password_enabled": true,
    "security_groups": [],
    "service_offering": "t1.micro",
    "ssh_key": "MY_SSHKEY",
    "state": "Running",
    "tags": [],
    "template": "Debian 9 - Minimal - 64bits",
    "user_data": "",
    "zone": "EU-FR-IKDC1-Z1-ADV"
}

In diesem Beispiel stellen wir eine Debian 9-Instanz in der erweiterten Zone (EU-FR-IKDC1-Z1-ADV) bereit und verwenden das Rechenangebot "t1.micro" in unserem Netzwerk mit dem Namen "My-Network-Z1" und unserem SSH-Schlüsselpaar mit dem Namen "MY_SSHKEY".

Um alle verwendbaren Parameter und andere Beispiele zu sehen, können Sie die ansible-doc des Moduls "cs_instance" verwenden:

$ ansible-doc cs_instance
> CS_INSTANCE    (/usr/lib/python2.7/site-packages/ansible/modules/cloud/cloudstack/cs_instance.py)

  Deploy, start, update, scale, restart, restore, stop and destroy instances.

Options (= is mandatory):

- account
        Account the instance is related to.
        [Default: None]
- affinity_groups
        Affinity groups names to be applied to the new instance.
        [Default: []]
- api_http_method
        HTTP method used.
        (Choices: get, post)[Default: get]
- api_key
        API key of the CloudStack API.
        [Default: None]
- api_region
        Name of the ini section in the `cloustack.ini' file.
        [Default: cloudstack]
- api_secret
        Secret key of the CloudStack API.
        [Default: None]
- api_timeout
        HTTP timeout.
        [Default: 10]
- api_url
        URL of the CloudStack API e.g. https://cloud.example.com/client/api.
        [Default: None]
- cpu
        The number of CPUs to allocate to the instance, used with custom service offerings
        [Default: None]
- cpu_speed
        The clock speed/shares allocated to the instance, used with custom service offerings
        [Default: None]
- disk_offering
        Name of the disk offering to be used.
        [Default: None]
- disk_size
        Disk size in GByte required if deploying instance from ISO.
        [Default: None]
...

Hinweis: Die Ausgabe des Befehls ist aufgrund seiner Länge absichtlich gekürzt.

Bereitstellung einer Instanz mit einem Ansible-Playbook

Auf die gleiche Weise wie oben müssen Sie zunächst die Konfigurationsdatei ".cloudstack.ini" des Moduls "cs_instance" von Ansible erstellen und ausfüllen/anpassen:

[CloudIkoulaOne]
endpoint = https://cloudstack.ikoula.com/client/api
key = <clé API de votre utilisateur/compte Cloud IKOULA One>
secret = <clé privée de votre utilisateur/compte Cloud IKOULA One>
timeout = 30

Dann müssen Sie nur eine Playbook-Datei (yml-Erweiterung / YAML-Format) erstellen, wie unten beschrieben, und die Werte der Parameter (Name Ihrer Instanz, Name des Netzwerks usw.) und die Parameter selbst (ob Sie z. B. ein SSH-Schlüsselpaar verwenden müssen/wollen oder nicht) anpassen:

Beispiel für ein Playbook für die Bereitstellung einer Instanz in einer erweiterten Zone:

$ cat deploy_instance_adv.yml
---

- hosts: all
  connection: local
  user: root

  tasks:

  - name: 'Create Debian instance in Cloud IKOULA One with Ansible Playbook'
    cs_instance:
      name: "<Nom de la VM>"
      state: present
      display_name: "<Nom de la VM>"
      template: "<Nom entre simples quotes ou ID du template CIO voulu>"
      api_region: "CloudIkoulaOne"
      zone: "<Nom de la zone voulu>"
      service_offering: "<Nom de l’offre de calcul voulu >"
      networks: "<Nom du réseau existant voulu>"
      ssh_key: "<Nom de la paire de clés ssh CIO existante>"
...

Beispiel für ein Playbook für die Bereitstellung einer Instanz in einer Basiszone (hier wird einfach der Netzwerkparameter durch den Sicherheitsgruppenparameter ersetzt und die Rückgabe der öffentlichen IP-Adresse, die der VM zugewiesen wurde, nach der Bereitstellung hinzugefügt):

$ cat deploy_instance_basic.yml
---

- hosts: all
  connection: local
  user: root

  tasks:

  - name: 'Create Debian instance in Cloud IKOULA One with Ansible Playbook'
    cs_instance:
      name: "<Nom de la VM>"
      state: present
      display_name: "<Nom de la VM>"
      template: "<Nom entre simples quotes ou ID du template CIO voulu>"
      api_region: "CloudIkoulaOne"
      zone: "<Nom de la zone voulu>"
      service_offering: "<Nom de l’offre de calcul voulu >"
      security_groups: "<Nom du groupe de sécurité existant voulu>"
      ssh_key: "<Nom de la paire de clés ssh CIO existante>"

  - name: "VM ip address:"
    debug:
      var: vminfo.default_ip
...


Nachdem die Parameter und ihre Werte angepasst wurden, folgt ein Beispiel für die Ausführung des Playbooks (passen Sie den Namen Ihrer Playbook-Datei gegebenenfalls an):

$ ansible-playbook -i "localhost," -c local deploy_instance_adv.yml

PLAY [all] ********************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [Create Debian instance in Cloud IKOULA One with Ansible Playbook] ********************************************************************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ********************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0

Catégorie :Cloud public Catégorie:API Catégorie :Cloud</Nom>