Difference between revisions of "Deploy your instances with Ansible"
Line 1: | Line 1: | ||
+ | <span data-link_translate_ja_title="Ansibleによるインスタンスのデプロイ" data-link_translate_ja_url="Ansibleによるインスタンスのデプロイ"></span>[[:ja:Ansibleによるインスタンスのデプロイ]][[ja:Ansibleによるインスタンスのデプロイ]] | ||
<span data-link_translate_zh_title="用Ansible部署你的实例" data-link_translate_zh_url="用Ansible部署你的实例"></span>[[:zh:用Ansible部署你的实例]][[zh:用Ansible部署你的实例]] | <span data-link_translate_zh_title="用Ansible部署你的实例" data-link_translate_zh_url="用Ansible部署你的实例"></span>[[:zh:用Ansible部署你的实例]][[zh:用Ansible部署你的实例]] | ||
<span data-link_translate_de_title="Stellen Sie Ihre Instanzen mit Ansible bereit" data-link_translate_de_url="Stellen Sie Ihre Instanzen mit Ansible bereit"></span>[[:de:Stellen Sie Ihre Instanzen mit Ansible bereit]][[de:Stellen Sie Ihre Instanzen mit Ansible bereit]] | <span data-link_translate_de_title="Stellen Sie Ihre Instanzen mit Ansible bereit" data-link_translate_de_url="Stellen Sie Ihre Instanzen mit Ansible bereit"></span>[[:de:Stellen Sie Ihre Instanzen mit Ansible bereit]][[de:Stellen Sie Ihre Instanzen mit Ansible bereit]] |
Revision as of 16:34, 29 July 2021
ja:Ansibleによるインスタンスのデプロイ
zh:用Ansible部署你的实例
de:Stellen Sie Ihre Instanzen mit Ansible bereit
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
fr:Deployer vos instances avec Ansible
This article has been created by an automatic translation software. You can view the article source here.
Description
We will see how to quickly deploy IKOULA One Cloud instances via the Ansible tool
First you will need to install Ansible (https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) then the "cs_instance" module (can be installed via "pip install cs" cf. https://docs.ansible.com/ansible/2.6/modules/cs_instance_module.html) allowing you to use the Cloud Ikoula One API, if not already done and have a Cloud IKOULA One account.
Ansible is available for most GNU/Linux distributions, MacOS but can also be used via Cygwin for example under Microsoft Windows.
Deploying an instance in one command with Ansible
You will first need to create and fill in/adapt the ".cloudstack.ini" configuration file of the "cs_instance" module of Ansible :
[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
Then you just need to run this command, adapting the values of the parameters (name of your instance, name of the network, etc.) and the parameters themselves (if you have/want to use an SSH key pair or not for example):
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>"
where "<Nom de l’offre de calcul voulu >" is the choice of :
"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)
Here is an example and the return from its execution:
$ 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 this example, we deploy a Debian 9 instance in the advanced zone (EU-FR-IKDC1-Z1-ADV), using the compute offering "t1.micro" in our network named "My-Network-Z1" with our SSH key pair named "MY_SSHKEY"
To see all the usable parameters and other examples, you can use the ansible-doc of the "cs_instance" module:
$ 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] ...
Note: the output of the command is deliberately truncated due to its length.
Deploying an instance with an Ansible playbook
In the same way as above you must first create and fill in/adapt the ".cloudstack.ini" configuration file of the "cs_instance" module of Ansible :
[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
Then you just need to create a playbook file (yml extension / YAML format), as below, adapting the values of the parameters (name of your instance, name of the network, etc.) and the parameters themselves (if you have/want to use an SSH key pair or not for example) :
Example of a playbook for deploying an instance in an advanced 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>" ...
Example of a playbook for the deployment of an instance in a basic zone (where we simply replace the network parameter by the security groups parameter and add the post-deployment return of the public ip address assigned to the vm):
$ 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 ...
Once the parameters and their values have been adapted, here is an example of how to run the playbook (adapt the name of your playbook file if necessary):
$ 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>