| 1 |
.. |
| 2 |
Copyright (c) Ansible Project |
| 3 |
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 4 |
SPDX-License-Identifier: GPL-3.0-or-later |
| 5 |
|
| 6 |
.. _ansible_collections.community.general.docsite.guide_alicloud: |
| 7 |
|
| 8 |
Alibaba Cloud Compute Services Guide |
| 9 |
==================================== |
| 10 |
|
| 11 |
Introduction |
| 12 |
```````````` |
| 13 |
|
| 14 |
The community.general collection contains several modules for controlling and managing Alibaba Cloud Compute Services (Alicloud). This guide |
| 15 |
explains how to use the Alicloud Ansible modules together. |
| 16 |
|
| 17 |
All Alicloud modules require ``footmark`` - install it on your control machine with ``pip install footmark``. |
| 18 |
|
| 19 |
Cloud modules, including Alicloud modules, are usually executed on your local machine (the control machine) with ``connection: local``, rather than on remote machines defined in your hosts. |
| 20 |
|
| 21 |
Normally, you'll use the following pattern for plays that provision Alicloud resources: |
| 22 |
|
| 23 |
.. code-block:: yaml |
| 24 |
|
| 25 |
- hosts: localhost |
| 26 |
connection: local |
| 27 |
vars: |
| 28 |
... |
| 29 |
tasks: |
| 30 |
- ... |
| 31 |
|
| 32 |
Authentication |
| 33 |
`````````````` |
| 34 |
|
| 35 |
You can specify your Alicloud authentication credentials (access key and secret key) by passing them as |
| 36 |
environment variables or by storing them in a vars file. |
| 37 |
|
| 38 |
To pass authentication credentials as environment variables: |
| 39 |
|
| 40 |
.. code-block:: console |
| 41 |
|
| 42 |
export ALICLOUD_ACCESS_KEY='Alicloud123' |
| 43 |
export ALICLOUD_SECRET_KEY='AlicloudSecret123' |
| 44 |
|
| 45 |
To store authentication credentials in a vars file, encrypt them with :ref:`Ansible Vault <vault>` to keep them secure, then list them: |
| 46 |
|
| 47 |
.. code-block:: yaml |
| 48 |
|
| 49 |
--- |
| 50 |
alicloud_access_key: "--REMOVED--" |
| 51 |
alicloud_secret_key: "--REMOVED--" |
| 52 |
|
| 53 |
Note that if you store your credentials in a vars file, you need to refer to them in each Alicloud module. For example: |
| 54 |
|
| 55 |
.. code-block:: yaml+jinja |
| 56 |
|
| 57 |
- community.general.ali_instance: |
| 58 |
alicloud_access_key: "{{ alicloud_access_key }}" |
| 59 |
alicloud_secret_key: "{{ alicloud_secret_key }}" |
| 60 |
image_id: "..." |
| 61 |
|
| 62 |
Provisioning |
| 63 |
```````````` |
| 64 |
|
| 65 |
Alicloud modules create Alicloud ECS instances (:ansplugin:`community.general.ali_instance#module`) and retrieve information on these (:ansplugin:`community.general.ali_instance_info#module`). |
| 66 |
|
| 67 |
You can use the ``count`` parameter to control the number of resources you create or terminate. For example, if you want exactly 5 instances tagged ``NewECS``, set the ``count`` of instances to 5 and the ``count_tag`` to ``NewECS``, as shown in the last task of the example playbook below. If there are no instances with the tag ``NewECS``, the task creates 5 new instances. If there are 2 instances with that tag, the task creates 3 more. If there are 8 instances with that tag, the task terminates 3 of those instances. |
| 68 |
|
| 69 |
If you do not specify a ``count_tag``, the task creates the number of instances you specify in ``count`` with the ``instance_name`` you provide. |
| 70 |
|
| 71 |
.. code-block:: yaml+jinja |
| 72 |
|
| 73 |
# alicloud_setup.yml |
| 74 |
|
| 75 |
- hosts: localhost |
| 76 |
connection: local |
| 77 |
|
| 78 |
tasks: |
| 79 |
- name: Create a set of instances |
| 80 |
community.general.ali_instance: |
| 81 |
instance_type: ecs.n4.small |
| 82 |
image_id: "{{ ami_id }}" |
| 83 |
instance_name: "My-new-instance" |
| 84 |
instance_tags: |
| 85 |
Name: NewECS |
| 86 |
Version: 0.0.1 |
| 87 |
count: 5 |
| 88 |
count_tag: |
| 89 |
Name: NewECS |
| 90 |
allocate_public_ip: true |
| 91 |
max_bandwidth_out: 50 |
| 92 |
register: create_instance |
| 93 |
|
| 94 |
In the example playbook above, data about the instances created by this playbook is saved in the variable defined by the ``register`` keyword in the task. |
| 95 |
|
| 96 |
Each Alicloud module offers a variety of parameter options. Not all options are demonstrated in the above example. See each individual module for further details and examples. |