ansible/docs/docsite/rst/scenario_guides/guide_vultr.rst

172 lines
4.4 KiB
ReStructuredText
Raw Normal View History

2018-08-31 16:42:07 +02:00
Vultr Guide
===========
Ansible offers a set of modules to interact with `Vultr <https://www.vultr.com>`_ cloud platform.
This set of module forms a framework that allows one to easily manage and orchestrate one's infrastructure on Vultr cloud platform.
2018-08-31 16:42:07 +02:00
Requirements
------------
There is actually no technical requirement; simply an already created Vultr account.
Configuration
-------------
Vultr modules offer a rather flexible way with regard to configuration.
Configuration is read in that order:
- Environment Variables (eg. ``VULTR_API_KEY``, ``VULTR_API_TIMEOUT``)
- File specified by environment variable ``VULTR_API_CONFIG``
- ``vultr.ini`` file located in current working directory
- ``$HOME/.vultr.ini``
Ini file are structured this way:
.. code-block:: ini
[default]
key = MY_API_KEY
timeout = 60
[personal_account]
key = MY_PERSONAL_ACCOUNT_API_KEY
timeout = 30
If ``VULTR_API_ACCOUNT`` environment variable or ``api_account`` module parameter is not specified, modules will look for the section named "default".
2018-08-31 16:42:07 +02:00
Authentication
--------------
Before using the Ansible modules to interact with Vultr, ones need an API key.
If one doesn't own one yet, log in to `Vultr <https://www.vultr.com>`_ go to Account, then API, enable API then the API key should show up.
Ensure you allow the usage of the API key from the proper IP addresses.
Refer to the Configuration section to find out where to put this information.
To check that everything is working properly run the following command:
.. code-block:: console
2019-08-24 17:54:17 +02:00
#> VULTR_API_KEY=XXX ansible -m vultr_account_info localhost
2018-08-31 16:42:07 +02:00
localhost | SUCCESS => {
"changed": false,
2019-08-24 17:54:17 +02:00
"vultr_account_info": {
2018-08-31 16:42:07 +02:00
"balance": -8.9,
"last_payment_amount": -10.0,
"last_payment_date": "2018-07-21 11:34:46",
"pending_charges": 6.0
},
"vultr_api": {
"api_account": "default",
"api_endpoint": "https://api.vultr.com",
"api_retries": 5,
"api_timeout": 60
}
}
If a similar output displays then everything is setup properly, else please ensure the proper ``VULTR_API_KEY`` has been specified and that Access Control on Vultr > Account > API page are accurate.
Usage
-----
Since `Vultr <https://www.vultr.com>`_ offers a public API, the execution of the module to manage the infrastructure on their platform will happen on localhost. This translates to:
.. code-block:: yaml
---
- hosts: localhost
tasks:
- name: Create a 10G volume
vultr_block_storage:
name: my_disk
size: 10
region: New Jersey
Doc backportapalooza 2 (#70440) * doc: avoid mix of single and double quotes (#70115) Avoid mix of single and double quotes in the `ternary`, this way we can copy/past the example without any surprise. (cherry picked from commit b491f776b9cf50f17df6917597dec935360b5887) * document FQCN for M() and :seealso: in DOCUMENTATION blocks (#70245) * document FQCN for M() in DOCUMENTATION blocks * add note about c (cherry picked from commit 83f6e4850b12532dc244eb0b436b1d0a49dc09a9) * Fix bullet points in intro_getting_started.rst. (#70365) The layout was jumbled due to issues with whitespace. (cherry picked from commit dc6f4b650227bbe07996deb9998b038a67810d7d) * Add steps for how to create changelog.rst for a collection (#70262) * Update docs/docsite/rst/dev_guide/developing_collections.rst * add steps to create changelogs, add sentence about not using the tool * add note for rerunning the command Co-authored-by: Felix Fontein <felix@fontein.de> (cherry picked from commit 5a28b2b86cf1cc9a8b2c5ef80bbdd1aa5b5c72dd) * ansible-doc: avoid problems with YAML anchors when formatting man page (#70045) * Avoid problems with YAML anchors when formatting man page. * Add changelog. (cherry picked from commit 5e4f708241815ad4d5fa0aef0574310c5451029a) * Minor grammatical fix (#70405) 'you' -> 'your' (cherry picked from commit a1ac595d426f61001a718698c89b3b0e65ff56e2) * incorporate minimalism feedback on filters page (#70366) Co-authored-by: Alicia Cozine <acozine@users.noreply.github.com> (cherry picked from commit c89f3cda9e4b8e6bb45210bb485dbb6f6dee98c3) * more correct info about role main.yml (#70326) fixes #40496 (cherry picked from commit 5d3d097de381a0784b3b38ffeaf3111183d9085c) * Fix a small typo in cache plugin description @ `config/base.yml` PR #70420 (cherry picked from commit 626df08d9d2f11d72a88bad5c51c17bfb3c2e53e) * with_sequence: example using vars (#69369) Added an example for using vars in with_sequence. Fixes: #68836 Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com> (cherry picked from commit 5709173c321b4f8ac1ae637b3e739f077c7d9d54) * Update pull.py (#70393) (cherry picked from commit 46ad3c11624677a6ccb2134c364c2b8454563f32) * Update playbooks.rst (#70317) (cherry picked from commit 7c90a2d2a6e56d1a1dd42a46157f455748ba24e1) * Add documentation for ipaddr filters (#70343) (cherry picked from commit 9eb904ea61344f6dc8251aba2595d64d31ff735a) * update platform table with links to collections (#70373) (cherry picked from commit aa59c23aed85f7e675b86663b5bc13172f8ee350) * Add description of collections and become_exe keywords (#68055) * Add description of collections keyword * Update based on feedback. - Add link to become plugins. - Add note about how the collections keyword works with roles. (cherry picked from commit 5833af9e2a5cd1d25e85995fc9d930891d5e26fd) Co-authored-by: Gonéri Le Bouder <goneri@lebouder.net> Co-authored-by: Mark Sanders <ziplokk.mark.sanders@gmail.com> Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Sir Mobus Gochfulshigan Dorphin Esquire XXIII <celestialtuba@gmail.com> Co-authored-by: Alicia Cozine <879121+acozine@users.noreply.github.com> Co-authored-by: Brian Coca <bcoca@users.noreply.github.com> Co-authored-by: Michael Scherer <mscherer@users.noreply.github.com> Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com> Co-authored-by: Ethan <smithe2413@gmail.com> Co-authored-by: jafiala <56597272+jafiala@users.noreply.github.com> Co-authored-by: Baptiste Mille-Mathias <baptiste.millemathias@gmail.com> Co-authored-by: Sam Doran <sdoran@redhat.com>
2020-07-08 23:05:41 +02:00
From that point on, only your creativity is the limit. Make sure to read the documentation of the `available modules <https://docs.ansible.com/ansible/latest/modules/list_of_cloud_modules.html#vultr>`_.
2018-08-31 16:42:07 +02:00
Dynamic Inventory
-----------------
Ansible provides a dynamic inventory plugin for `Vultr <https://www.vultr.com>`_.
The configuration process is exactly the same as the one for the modules.
To be able to use it you need to enable it first by specifying the following in the ``ansible.cfg`` file:
2018-08-31 16:42:07 +02:00
.. code-block:: ini
[inventory]
enable_plugins=vultr
And provide a configuration file to be used with the plugin, the minimal configuration file looks like this:
.. code-block:: yaml
---
plugin: vultr
To list the available hosts one can simply run:
.. code-block:: console
#> ansible-inventory -i vultr.yml --list
2018-08-31 16:42:07 +02:00
For example, this allows you to take action on nodes grouped by location or OS name:
2018-08-31 16:42:07 +02:00
.. code-block:: yaml
---
- hosts: Amsterdam
tasks:
- name: Rebooting the machine
shell: reboot
become: True
Integration tests
-----------------
Ansible includes integration tests for all Vultr modules.
These tests are meant to run against the public Vultr API and that is why they require a valid key to access the API.
Prepare the test setup:
.. code-block:: shell
$ cd ansible # location the ansible source is
$ source ./hacking/env-setup
Set the Vultr API key:
.. code-block:: shell
$ cd test/integration
$ cp cloud-config-vultr.ini.template cloud-config-vultr.ini
$ vi cloud-config-vultr.ini
Run all Vultr tests:
.. code-block:: shell
$ ansible-test integration cloud/vultr/ -v --diff --allow-unsupported
2019-08-24 17:54:17 +02:00
To run a specific test, e.g. vultr_account_info:
.. code-block:: shell
2019-08-24 17:54:17 +02:00
$ ansible-test integration cloud/vultr/vultr_account_info -v --diff --allow-unsupported