├── .github ├── dependabot.yml └── workflows │ ├── integration.yml │ ├── publish.yml │ └── sanity.yml ├── .gitignore ├── CHANGELOG.rst ├── CONTRIBUTING.md ├── COPYING ├── README.md ├── changelogs ├── .gitignore ├── changelog.yaml ├── config.yaml └── fragments │ └── .keep ├── codecov.yml ├── galaxy.yml ├── meta └── runtime.yml ├── plugins ├── doc_fragments │ ├── __init__.py │ └── vultr.py ├── inventory │ ├── __init__.py │ └── vultr.py ├── module_utils │ └── vultr.py └── modules │ ├── __init__.py │ ├── vultr_account_info.py │ ├── vultr_block_storage.py │ ├── vultr_block_storage_info.py │ ├── vultr_dns_domain.py │ ├── vultr_dns_domain_info.py │ ├── vultr_dns_record.py │ ├── vultr_firewall_group.py │ ├── vultr_firewall_group_info.py │ ├── vultr_firewall_rule.py │ ├── vultr_network.py │ ├── vultr_network_info.py │ ├── vultr_os_info.py │ ├── vultr_plan_baremetal_info.py │ ├── vultr_plan_info.py │ ├── vultr_region_info.py │ ├── vultr_server.py │ ├── vultr_server_baremetal.py │ ├── vultr_server_info.py │ ├── vultr_ssh_key.py │ ├── vultr_ssh_key_info.py │ ├── vultr_startup_script.py │ ├── vultr_startup_script_info.py │ ├── vultr_user.py │ └── vultr_user_info.py └── tests ├── integration └── targets │ ├── vultr_account_info │ ├── aliases │ └── tasks │ │ └── main.yml │ ├── vultr_block_storage │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_block_storage_info │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_dns_domain │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_dns_domain_info │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_dns_record │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ ├── create_record.yml │ │ ├── main.yml │ │ ├── record.yml │ │ ├── remove_record.yml │ │ ├── test_fail_multiple.yml │ │ └── update_record.yml │ ├── vultr_firewall_group │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_firewall_group_info │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_firewall_rule │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_network │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_network_info │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_os_info │ ├── aliases │ └── tasks │ │ └── main.yml │ ├── vultr_plan_baremetal_info │ ├── aliases │ └── tasks │ │ └── main.yml │ ├── vultr_plan_info │ ├── aliases │ └── tasks │ │ └── main.yml │ ├── vultr_region_info │ ├── aliases │ └── tasks │ │ └── main.yml │ ├── vultr_server │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_server_baremetal │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_server_info │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_ssh_key │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_ssh_key_info │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_startup_script │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_startup_script_info │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ ├── vultr_user │ ├── aliases │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml │ └── vultr_user_info │ ├── aliases │ ├── defaults │ └── main.yml │ └── tasks │ └── main.yml └── sanity └── ignore-2.10.txt /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Set update schedule for GitHub Actions 2 | --- 3 | version: 2 4 | updates: 5 | - package-ecosystem: "github-actions" 6 | directory: "/" 7 | schedule: 8 | interval: "weekly" 9 | -------------------------------------------------------------------------------- /.github/workflows/integration.yml: -------------------------------------------------------------------------------- 1 | name: Collection integration 2 | 3 | on: 4 | push: 5 | schedule: 6 | - cron: 31 6 * * 2 # Run weekly 7 | 8 | jobs: 9 | integration-test: 10 | name: Integration test using Python ${{ matrix.python-version }} 11 | runs-on: ubuntu-20.04 12 | defaults: 13 | run: 14 | working-directory: ansible_collections/ngine_io/vultr 15 | strategy: 16 | fail-fast: false 17 | matrix: 18 | runner-python-version: 19 | - 3.6 20 | python-version: 21 | - 3.6 22 | - 2.7 23 | steps: 24 | - name: Check out code 25 | uses: actions/checkout@v3 26 | with: 27 | path: ansible_collections/ngine_io/vultr 28 | 29 | - name: Set up Python ${{ matrix.python-version }} 30 | uses: actions/setup-python@v4 31 | with: 32 | python-version: ${{ matrix.python-version }} 33 | 34 | - name: Install ansible and collection dependencies 35 | run: | 36 | python -m pip install --upgrade pip 37 | pip install ansible 38 | 39 | - name: Build and install collection 40 | run: | 41 | ansible-galaxy collection build . 42 | ansible-galaxy collection install *.gz 43 | 44 | - name: Add config file 45 | env: 46 | CONFIG_FILE: ${{ secrets.CONFIG_FILE }} 47 | run: | 48 | echo "$CONFIG_FILE" > tests/integration/cloud-config-vultr.ini 49 | 50 | - name: Run the tests 51 | run: >- 52 | ansible-test 53 | integration 54 | --docker 55 | -v 56 | --diff 57 | --color 58 | --retry-on-error 59 | --python ${{ matrix.python-version }} 60 | --continue-on-error 61 | --coverage 62 | smoke/vultr/ 63 | 64 | - name: Generate coverage report 65 | run: >- 66 | ansible-test 67 | coverage xml 68 | -v 69 | --requirements 70 | --group-by command 71 | --group-by version 72 | - uses: codecov/codecov-action@v3 73 | with: 74 | fail_ci_if_error: false 75 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Upload release to Galaxy 2 | 3 | on: 4 | release: 5 | types: [created] 6 | jobs: 7 | call-sanity-workflow: 8 | uses: ./.github/workflows/sanity.yml 9 | deploy: 10 | runs-on: ubuntu-latest 11 | defaults: 12 | run: 13 | working-directory: ansible_collections/ngine_io/vultr 14 | steps: 15 | - uses: actions/checkout@v3 16 | with: 17 | path: ansible_collections/ngine_io/vultr 18 | 19 | - name: Set up Python 20 | uses: actions/setup-python@v4 21 | with: 22 | python-version: "3.x" 23 | 24 | - name: Install dependencies 25 | run: | 26 | python -m pip install --upgrade pip 27 | pip install ansible 28 | 29 | - name: Build and publish 30 | env: 31 | ANSIBLE_GALAXY_API_KEY: ${{ secrets.ANSIBLE_GALAXY_API_KEY }} 32 | run: | 33 | ansible-galaxy collection build . 34 | ansible-galaxy collection publish *.tar.gz --api-key $ANSIBLE_GALAXY_API_KEY 35 | -------------------------------------------------------------------------------- /.github/workflows/sanity.yml: -------------------------------------------------------------------------------- 1 | name: Sanity 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | schedule: 8 | - cron: "5 12 * * *" 9 | pull_request: 10 | workflow_call: 11 | workflow_dispatch: 12 | 13 | jobs: 14 | sanity: 15 | name: Sanity (${{ matrix.ansible }}) 16 | runs-on: ubuntu-20.04 17 | defaults: 18 | run: 19 | working-directory: ansible_collections/ngine_io/vultr 20 | strategy: 21 | matrix: 22 | ansible: 23 | - stable-2.14 24 | - stable-2.13 25 | - stable-2.12 26 | - devel 27 | steps: 28 | - name: Check out code 29 | uses: actions/checkout@v3 30 | with: 31 | path: ansible_collections/ngine_io/vultr 32 | 33 | - name: Set up Python 34 | uses: actions/setup-python@v4 35 | with: 36 | python-version: "3.10" 37 | 38 | - name: Install ansible-base (${{ matrix.ansible }}) 39 | run: pip install https://github.com/ansible/ansible/archive/${{ matrix.ansible }}.tar.gz --disable-pip-version-check 40 | 41 | - name: Run sanity tests 42 | run: ansible-test sanity --docker -v --color 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | tests/output/ 2 | cloud-config-vultr.ini 3 | -------------------------------------------------------------------------------- /CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | ============================== 2 | Vultr Collection Release Notes 3 | ============================== 4 | 5 | .. contents:: Topics 6 | 7 | 8 | v1.1.3 9 | ====== 10 | 11 | Bugfixes 12 | -------- 13 | 14 | - iventory - Fixed ``allowed_bandwidth_gb`` to be returned as float (https://github.com/ngine-io/ansible-collection-vultr/pull/35). 15 | - vultr_server - Fixed ``allowed_bandwidth_gb`` to be returned as float (https://github.com/ngine-io/ansible-collection-vultr/pull/35). 16 | - vultr_server_baremetal - Fixed ``allowed_bandwidth_gb`` to be returned as float (https://github.com/ngine-io/ansible-collection-vultr/pull/35). 17 | 18 | v1.1.2 19 | ====== 20 | 21 | Release Summary 22 | --------------- 23 | 24 | This collection has turned into maintenance mode. We encourage you to add new features to its successor at https://galaxy.ansible.com/vultr/cloud. 25 | 26 | 27 | Minor Changes 28 | ------------- 29 | 30 | - Documentation fixes. 31 | 32 | v1.1.1 33 | ====== 34 | 35 | Bugfixes 36 | -------- 37 | 38 | - vultr_server - Fix user data not handled correctly (https://github.com/ngine-io/ansible-collection-vultr/pull/26). 39 | 40 | v1.1.0 41 | ====== 42 | 43 | Minor Changes 44 | ------------- 45 | 46 | - vultr_block_storage - Included ability to resize, attach and detach Block Storage Volumes. 47 | 48 | v1.0.0 49 | ====== 50 | 51 | v0.3.0 52 | ====== 53 | 54 | Minor Changes 55 | ------------- 56 | 57 | - vultr_server_info, vultr_server - Improved handling of discontinued plans (https://github.com/ansible/ansible/issues/66707). 58 | 59 | Bugfixes 60 | -------- 61 | 62 | - vultr - Fixed the issue retry max delay param was ignored. 63 | 64 | New Modules 65 | ----------- 66 | 67 | - vultr_plan_baremetal_info - Gather information about the Vultr Bare Metal plans available. 68 | - vultr_server_baremetal - Manages baremetal servers on Vultr. 69 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Any contribution is welcome and we only ask contributors to: 4 | 5 | - Create an issues for any significant contribution that would change a large portion of the code base. 6 | - Provide at least integration tests for any contribution 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # !!! NOTE !!! 3 | 4 | This collection is in maintance mode: bug fixes only. For new features, please visit https://github.com/vultr/ansible-collection-vultr/. 5 | 6 | ---- 7 | 8 | ![Collection integration](https://github.com/ngine-io/ansible-collection-vultr/workflows/Collection%20integration/badge.svg) 9 | [![Codecov](https://img.shields.io/codecov/c/github/ngine-io/ansible-collection-vultr)](https://codecov.io/gh/ngine-io/ansible-collection-vultr) 10 | [![License](https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg)](LICENSE) 11 | 12 | # Ansible Collection for Vultr Cloud 13 | 14 | This collection provides a series of Ansible modules and plugins for interacting with the [Vultr](https://www.vultr.com) Cloud. 15 | 16 | ## Requirements 17 | 18 | - ansible version >= 2.9 19 | 20 | ## Installation 21 | 22 | To install the collection hosted in Galaxy: 23 | 24 | ```bash 25 | ansible-galaxy collection install ngine_io.vultr 26 | ``` 27 | 28 | To upgrade to the latest version of the collection: 29 | 30 | ```bash 31 | ansible-galaxy collection install ngine_io.vultr --force 32 | ``` 33 | 34 | ## Usage 35 | 36 | ### Playbooks 37 | 38 | To use a module from Vultr collection, please reference the full namespace, collection name, and modules name that you want to use: 39 | 40 | ```yaml 41 | --- 42 | - name: Using Vultr collection 43 | hosts: localhost 44 | tasks: 45 | - ngine_io.vultr.vultr_server: 46 | ... 47 | ``` 48 | 49 | Or you can add full namepsace and collecton name in the `collections` element: 50 | 51 | ```yaml 52 | --- 53 | - name: Using Vultr collection 54 | hosts: localhost 55 | collections: 56 | - ngine_io.vultr 57 | tasks: 58 | - vultr_server: 59 | ... 60 | ``` 61 | 62 | ### Roles 63 | 64 | For existing Ansible roles, please also reference the full namespace, collection name, and modules name which used in tasks instead of just modules name. 65 | 66 | ### Plugins 67 | 68 | To use a pluign, please reference the full namespace, collection name, and plugins name that you want to use: 69 | 70 | ```yaml 71 | plugin: ngine_io.vultr.vultr 72 | ``` 73 | 74 | ## Contributing 75 | 76 | There are many ways in which you can participate in the project, for example: 77 | 78 | - Submit bugs and feature requests, and help us verify as they are checked in 79 | - Review source code changes 80 | - Review the documentation and make pull requests for anything from typos to new content 81 | - If you are interested in fixing issues and contributing directly to the code base, please see the [CONTRIBUTING](CONTRIBUTING.md) document. 82 | 83 | ## License 84 | 85 | GNU General Public License v3.0 86 | 87 | See [COPYING](COPYING) to see the full text. 88 | -------------------------------------------------------------------------------- /changelogs/.gitignore: -------------------------------------------------------------------------------- 1 | /.plugin-cache.yaml 2 | -------------------------------------------------------------------------------- /changelogs/changelog.yaml: -------------------------------------------------------------------------------- 1 | ancestor: null 2 | releases: 3 | 0.3.0: 4 | changes: 5 | bugfixes: 6 | - vultr - Fixed the issue retry max delay param was ignored. 7 | minor_changes: 8 | - vultr_server_info, vultr_server - Improved handling of discontinued plans 9 | (https://github.com/ansible/ansible/issues/66707). 10 | fragments: 11 | - 66792-vultr-improve-plan.yml 12 | - 67437-vultr-fix-retry-max-delay-param.yml 13 | modules: 14 | - description: Gather information about the Vultr Bare Metal plans available. 15 | name: vultr_plan_baremetal_info 16 | namespace: '' 17 | - description: Manages baremetal servers on Vultr. 18 | name: vultr_server_baremetal 19 | namespace: '' 20 | release_date: '2020-07-03' 21 | 1.0.0: 22 | release_date: '2020-08-16' 23 | 1.1.0: 24 | changes: 25 | minor_changes: 26 | - vultr_block_storage - Included ability to resize, attach and detach Block 27 | Storage Volumes. 28 | fragments: 29 | - 14-attach-detach-and-resize-volumes.yml 30 | release_date: '2021-02-02' 31 | 1.1.1: 32 | changes: 33 | bugfixes: 34 | - vultr_server - Fix user data not handled correctly (https://github.com/ngine-io/ansible-collection-vultr/pull/26). 35 | fragments: 36 | - 26-fix-user-data.yml 37 | release_date: '2022-03-27' 38 | 1.1.2: 39 | changes: 40 | minor_changes: 41 | - Documentation fixes. 42 | release_summary: 'This collection has turned into maintenance mode. We encourage 43 | you to add new features to its successor at https://galaxy.ansible.com/vultr/cloud. 44 | 45 | ' 46 | fragments: 47 | - sanity.yml 48 | - summary.yml 49 | release_date: '2022-06-08' 50 | 1.1.3: 51 | changes: 52 | bugfixes: 53 | - iventory - Fixed ``allowed_bandwidth_gb`` to be returned as float (https://github.com/ngine-io/ansible-collection-vultr/pull/35). 54 | - vultr_server - Fixed ``allowed_bandwidth_gb`` to be returned as float (https://github.com/ngine-io/ansible-collection-vultr/pull/35). 55 | - vultr_server_baremetal - Fixed ``allowed_bandwidth_gb`` to be returned as 56 | float (https://github.com/ngine-io/ansible-collection-vultr/pull/35). 57 | fragments: 58 | - allowed_bandwidth_gb.yml 59 | release_date: '2023-01-23' 60 | -------------------------------------------------------------------------------- /changelogs/config.yaml: -------------------------------------------------------------------------------- 1 | changelog_filename_template: ../CHANGELOG.rst 2 | changelog_filename_version_depth: 0 3 | changes_file: changelog.yaml 4 | changes_format: combined 5 | keep_fragments: false 6 | mention_ancestor: true 7 | new_plugins_after_name: removed_features 8 | notesdir: fragments 9 | prelude_section_name: release_summary 10 | prelude_section_title: Release Summary 11 | sections: 12 | - - major_changes 13 | - Major Changes 14 | - - minor_changes 15 | - Minor Changes 16 | - - breaking_changes 17 | - Breaking Changes / Porting Guide 18 | - - deprecated_features 19 | - Deprecated Features 20 | - - removed_features 21 | - Removed Features (previously deprecated) 22 | - - security_fixes 23 | - Security Fixes 24 | - - bugfixes 25 | - Bugfixes 26 | - - known_issues 27 | - Known Issues 28 | title: Vultr Collection 29 | trivial_section_name: trivial 30 | -------------------------------------------------------------------------------- /changelogs/fragments/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngine-io/ansible-collection-vultr/81d1926818d1a9e0d5e485d73797c0f951395581/changelogs/fragments/.keep -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | --- 2 | coverage: 3 | precision: 2 4 | round: down 5 | range: "70...100" 6 | -------------------------------------------------------------------------------- /galaxy.yml: -------------------------------------------------------------------------------- 1 | --- 2 | authors: 3 | - "René Moser (@resmo)" 4 | - "Yanis Guenane (@Spredzy)" 5 | dependencies: {} 6 | description: "Ansible Collection for Vultr Cloud" 7 | documentation: "" 8 | homepage: "https://github.com/ngine-io/ansible-collection-vultr" 9 | issues: "https://github.com/ngine-io/ansible-collection-vultr/issues" 10 | license: GPL-3.0-or-later 11 | name: vultr 12 | namespace: ngine_io 13 | readme: README.md 14 | repository: "https://github.com/ngine-io/ansible-collection-vultr" 15 | tags: 16 | - cloud 17 | - vultr 18 | - ngine_io 19 | version: 1.1.3 20 | -------------------------------------------------------------------------------- /meta/runtime.yml: -------------------------------------------------------------------------------- 1 | requires_ansible: '>=2.9.10' 2 | action_groups: 3 | vultr: 4 | - vultr_user 5 | - vultr_plan_baremetal_info 6 | - vultr_user_info 7 | - vultr_block_storage 8 | - vultr_plan_info 9 | - vultr_ssh_key_info 10 | - vultr_network_info 11 | - vultr_firewall_group_info 12 | - vultr_ssh_key 13 | - vultr_dns_domain 14 | - vultr_server_info 15 | - vultr_dns_record 16 | - vultr_server_baremetal 17 | - vultr_block_storage_info 18 | - vultr_firewall_group 19 | - vultr_region_info 20 | - vultr_network 21 | - vultr_account_info 22 | - vultr_firewall_rule 23 | - vultr_dns_domain_info 24 | - vultr_server 25 | - vultr_startup_script 26 | - vultr_os_info 27 | - vultr_startup_script_info 28 | 29 | plugin_routing: 30 | modules: 31 | vr_account_facts: 32 | deprecation: 33 | removal_date: 2021-12-12 34 | warning_text: module was renamed, use ngine_io.vultr.vultr_account_info 35 | redirect: ngine_io.vultr.vultr_account_info 36 | vr_dns_domain: 37 | deprecation: 38 | removal_date: 2021-12-12 39 | warning_text: module was renamed, use ngine_io.vultr.vultr_dns_domain 40 | redirect: ngine_io.vultr.vultr_dns_domain 41 | vr_dns_record: 42 | deprecation: 43 | removal_date: 2021-12-12 44 | warning_text: module was renamed, use ngine_io.vultr.vultr_dns_record 45 | redirect: ngine_io.vultr.vultr_dns_record 46 | vr_firewall_group: 47 | deprecation: 48 | removal_date: 2021-12-12 49 | warning_text: module was renamed, use ngine_io.vultr.vultr_firewall_group 50 | redirect: ngine_io.vultr.vultr_firewall_group 51 | vr_firewall_rule: 52 | deprecation: 53 | removal_date: 2021-12-12 54 | warning_text: module was renamed, use ngine_io.vultr.vultr_firewall_rule 55 | redirect: ngine_io.vultr.vultr_firewall_rule 56 | vr_server: 57 | deprecation: 58 | removal_date: 2021-12-12 59 | warning_text: module was renamed, use ngine_io.vultr.vultr_server 60 | redirect: ngine_io.vultr.vultr_server 61 | vr_ssh_key: 62 | deprecation: 63 | removal_date: 2021-12-12 64 | warning_text: module was renamed, use ngine_io.vultr.vultr_ssh_key 65 | redirect: ngine_io.vultr.vultr_ssh_key 66 | vr_startup_script: 67 | deprecation: 68 | removal_date: 2021-12-12 69 | warning_text: module was renamed, use ngine_io.vultr.vultr_startup_script 70 | redirect: ngine_io.vultr.vultr_startup_script 71 | vr_user: 72 | deprecation: 73 | removal_date: 2021-12-12 74 | warning_text: module was renamed, use ngine_io.vultr.vultr_user 75 | redirect: ngine_io.vultr.vultr_user 76 | vultr_account_facts: 77 | deprecation: 78 | removal_date: 2021-12-12 79 | warning_text: module was renamed, use ngine_io.vultr.vultr_account_info 80 | redirect: ngine_io.vultr.vultr_account_info 81 | vultr_block_storage_facts: 82 | deprecation: 83 | removal_date: 2021-12-12 84 | warning_text: module was renamed, use ngine_io.vultr.vultr_block_storage_info 85 | redirect: ngine_io.vultr.vultr_block_storage_info 86 | vultr_dns_domain_facts: 87 | deprecation: 88 | removal_date: 2021-12-12 89 | warning_text: module was renamed, use ngine_io.vultr.vultr_dns_domain_info 90 | redirect: ngine_io.vultr.vultr_dns_domain_info 91 | vultr_firewall_group_facts: 92 | deprecation: 93 | removal_date: 2021-12-12 94 | warning_text: module was renamed, use ngine_io.vultr.vultr_firewall_group_info 95 | redirect: ngine_io.vultr.vultr_firewall_group_info 96 | vultr_network_facts: 97 | deprecation: 98 | removal_date: 2021-12-12 99 | warning_text: module was renamed, use ngine_io.vultr.vultr_network_info 100 | redirect: ngine_io.vultr.vultr_network_info 101 | vultr_os_facts: 102 | deprecation: 103 | removal_date: 2021-12-12 104 | warning_text: module was renamed, use ngine_io.vultr.vultr_os_info 105 | redirect: ngine_io.vultr.vultr_os_info 106 | vultr_plan_facts: 107 | deprecation: 108 | removal_date: 2021-12-12 109 | warning_text: module was renamed, use ngine_io.vultr.vultr_plan_info 110 | redirect: ngine_io.vultr.vultr_plan_info 111 | vultr_region_facts: 112 | deprecation: 113 | removal_date: 2021-12-12 114 | warning_text: module was renamed, use ngine_io.vultr.vultr_region_info 115 | redirect: ngine_io.vultr.vultr_region_info 116 | vultr_server_facts: 117 | deprecation: 118 | removal_date: 2021-12-12 119 | warning_text: module was renamed, use ngine_io.vultr.vultr_server_info 120 | redirect: ngine_io.vultr.vultr_server_info 121 | vultr_ssh_key_facts: 122 | deprecation: 123 | removal_date: 2021-12-12 124 | warning_text: module was renamed, use ngine_io.vultr.vultr_ssh_key_info 125 | redirect: ngine_io.vultr.vultr_ssh_key_info 126 | vultr_startup_script_facts: 127 | deprecation: 128 | removal_date: 2021-12-12 129 | warning_text: module was renamed, use ngine_io.vultr.vultr_startup_script_info 130 | redirect: ngine_io.vultr.vultr_startup_script_info 131 | vultr_user_facts: 132 | deprecation: 133 | removal_date: 2021-12-12 134 | warning_text: module was renamed, use ngine_io.vultr.vultr_user_info 135 | redirect: ngine_io.vultr.vultr_user_info 136 | -------------------------------------------------------------------------------- /plugins/doc_fragments/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngine-io/ansible-collection-vultr/81d1926818d1a9e0d5e485d73797c0f951395581/plugins/doc_fragments/__init__.py -------------------------------------------------------------------------------- /plugins/doc_fragments/vultr.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | # Copyright (c) 2017 René Moser 4 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 | from __future__ import absolute_import, division, print_function 6 | __metaclass__ = type 7 | 8 | 9 | class ModuleDocFragment(object): 10 | 11 | # Standard documentation fragment 12 | DOCUMENTATION = r''' 13 | options: 14 | api_key: 15 | description: 16 | - API key of the Vultr API. 17 | - The ENV variable C(VULTR_API_KEY) is used as default, when defined. 18 | type: str 19 | api_timeout: 20 | description: 21 | - HTTP timeout to Vultr API. 22 | - The ENV variable C(VULTR_API_TIMEOUT) is used as default, when defined. 23 | - Fallback value is 60 seconds if not specified. 24 | type: int 25 | api_retries: 26 | description: 27 | - Amount of retries in case of the Vultr API retuns an HTTP 503 code. 28 | - The ENV variable C(VULTR_API_RETRIES) is used as default, when defined. 29 | - Fallback value is 5 retries if not specified. 30 | type: int 31 | api_retry_max_delay: 32 | description: 33 | - Retry backoff delay in seconds is exponential up to this max. value, in seconds. 34 | - The ENV variable C(VULTR_API_RETRY_MAX_DELAY) is used as default, when defined. 35 | - Fallback value is 12 seconds. 36 | type: int 37 | api_account: 38 | description: 39 | - Name of the ini section in the C(vultr.ini) file. 40 | - The ENV variable C(VULTR_API_ACCOUNT) is used as default, when defined. 41 | type: str 42 | default: default 43 | api_endpoint: 44 | description: 45 | - URL to API endpint (without trailing slash). 46 | - The ENV variable C(VULTR_API_ENDPOINT) is used as default, when defined. 47 | - Fallback value is U(https://api.vultr.com) if not specified. 48 | type: str 49 | validate_certs: 50 | description: 51 | - Validate SSL certs of the Vultr API. 52 | type: bool 53 | default: yes 54 | requirements: 55 | - python >= 2.6 56 | notes: 57 | - Also see the API documentation on https://www.vultr.com/api/. 58 | ''' 59 | -------------------------------------------------------------------------------- /plugins/inventory/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngine-io/ansible-collection-vultr/81d1926818d1a9e0d5e485d73797c0f951395581/plugins/inventory/__init__.py -------------------------------------------------------------------------------- /plugins/inventory/vultr.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright (c) 2018, Yanis Guenane 3 | # Copyright (c) 2019, René Moser 4 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 | 6 | from __future__ import (absolute_import, division, print_function) 7 | 8 | __metaclass__ = type 9 | 10 | DOCUMENTATION = r''' 11 | name: vultr 12 | author: 13 | - Yanis Guenane (@Spredzy) 14 | - René Moser (@resmo) 15 | short_description: Vultr inventory source 16 | extends_documentation_fragment: 17 | - constructed 18 | description: 19 | - Get inventory hosts from Vultr public cloud. 20 | - Uses an YAML configuration file ending with either I(vultr.yml) or I(vultr.yaml) to set parameter values (also see examples). 21 | - Uses I(api_config), I(~/.vultr.ini), I(./vultr.ini) or C(VULTR_API_CONFIG) pointing to a Vultr credentials INI file 22 | (see U(https://docs.ansible.com/ansible/latest/scenario_guides/guide_vultr.html)). 23 | options: 24 | plugin: 25 | description: Token that ensures this is a source file for the 'vultr' plugin. 26 | type: string 27 | required: True 28 | choices: [ vultr ] 29 | api_account: 30 | description: Specify the account to be used. 31 | type: string 32 | default: default 33 | api_config: 34 | description: Path to the vultr configuration file. If not specified will be taken from regular Vultr configuration. 35 | type: path 36 | env: 37 | - name: VULTR_API_CONFIG 38 | api_key: 39 | description: Vultr API key. If not specified will be taken from regular Vultr configuration. 40 | type: string 41 | env: 42 | - name: VULTR_API_KEY 43 | hostname: 44 | description: Field to match the hostname. Note v4_main_ip corresponds to the main_ip field returned from the API and name to label. 45 | type: string 46 | default: v4_main_ip 47 | choices: 48 | - v4_main_ip 49 | - v6_main_ip 50 | - name 51 | filter_by_tag: 52 | description: Only return servers filtered by this tag 53 | type: string 54 | ''' 55 | 56 | EXAMPLES = r''' 57 | # inventory_vultr.yml file in YAML format 58 | # Example command line: ansible-inventory --list -i inventory_vultr.yml 59 | 60 | # Group by a region as lower case and with prefix e.g. "vultr_region_amsterdam" and by OS without prefix e.g. "CentOS_7_x64" 61 | plugin: vultr 62 | keyed_groups: 63 | - prefix: vultr_region 64 | key: region | lower 65 | - separator: "" 66 | key: os 67 | 68 | # Pass a tag filter to the API 69 | plugin: vultr 70 | filter_by_tag: Cache 71 | ''' 72 | 73 | import json 74 | 75 | from ansible.errors import AnsibleError 76 | from ansible.plugins.inventory import BaseInventoryPlugin, Constructable 77 | from ansible.module_utils.six.moves import configparser 78 | from ansible.module_utils.urls import open_url 79 | from ansible.module_utils._text import to_native 80 | from ..module_utils.vultr import Vultr, VULTR_API_ENDPOINT, VULTR_USER_AGENT 81 | from ansible.module_utils.six.moves.urllib.parse import quote 82 | 83 | 84 | SCHEMA = { 85 | 'SUBID': dict(key='id'), 86 | 'label': dict(key='name'), 87 | 'date_created': dict(), 88 | 'allowed_bandwidth_gb': dict(convert_to='float'), 89 | 'auto_backups': dict(key='auto_backup_enabled', convert_to='bool'), 90 | 'current_bandwidth_gb': dict(), 91 | 'kvm_url': dict(), 92 | 'default_password': dict(), 93 | 'internal_ip': dict(), 94 | 'disk': dict(), 95 | 'cost_per_month': dict(convert_to='float'), 96 | 'location': dict(key='region'), 97 | 'main_ip': dict(key='v4_main_ip'), 98 | 'network_v4': dict(key='v4_network'), 99 | 'gateway_v4': dict(key='v4_gateway'), 100 | 'os': dict(), 101 | 'pending_charges': dict(convert_to='float'), 102 | 'power_status': dict(), 103 | 'ram': dict(), 104 | 'plan': dict(), 105 | 'server_state': dict(), 106 | 'status': dict(), 107 | 'firewall_group': dict(), 108 | 'tag': dict(), 109 | 'v6_main_ip': dict(), 110 | 'v6_network': dict(), 111 | 'v6_network_size': dict(), 112 | 'v6_networks': dict(), 113 | 'vcpu_count': dict(convert_to='int'), 114 | } 115 | 116 | 117 | def _load_conf(path, account): 118 | 119 | if path: 120 | conf = configparser.ConfigParser() 121 | conf.read(path) 122 | 123 | if not conf._sections.get(account): 124 | return None 125 | 126 | return dict(conf.items(account)) 127 | else: 128 | return Vultr.read_ini_config(account) 129 | 130 | 131 | def _retrieve_servers(api_key, tag_filter=None): 132 | api_url = '%s/v1/server/list' % VULTR_API_ENDPOINT 133 | if tag_filter is not None: 134 | api_url = api_url + '?tag=%s' % quote(tag_filter) 135 | 136 | try: 137 | response = open_url( 138 | api_url, headers={'API-Key': api_key, 'Content-type': 'application/json'}, 139 | http_agent=VULTR_USER_AGENT, 140 | ) 141 | servers_list = json.loads(response.read()) 142 | 143 | return servers_list.values() if servers_list else [] 144 | except ValueError: 145 | raise AnsibleError("Incorrect JSON payload") 146 | except Exception as e: 147 | raise AnsibleError("Error while fetching %s: %s" % (api_url, to_native(e))) 148 | 149 | 150 | class InventoryModule(BaseInventoryPlugin, Constructable): 151 | 152 | NAME = 'ngine_io.vultr.vultr' 153 | 154 | def verify_file(self, path): 155 | valid = False 156 | if super(InventoryModule, self).verify_file(path): 157 | if path.endswith(('vultr.yaml', 'vultr.yml')): 158 | valid = True 159 | return valid 160 | 161 | def parse(self, inventory, loader, path, cache=True): 162 | super(InventoryModule, self).parse(inventory, loader, path) 163 | self._read_config_data(path=path) 164 | 165 | conf = _load_conf(self.get_option('api_config'), self.get_option('api_account')) 166 | try: 167 | api_key = self.get_option('api_key') or conf.get('key') 168 | except Exception: 169 | raise AnsibleError('Could not find an API key. Check inventory file and Vultr configuration files.') 170 | 171 | hostname_preference = self.get_option('hostname') 172 | 173 | # Add a top group 'vultr' 174 | self.inventory.add_group(group='vultr') 175 | 176 | # Filter by tag is supported by the api with a query 177 | filter_by_tag = self.get_option('filter_by_tag') 178 | for server in _retrieve_servers(api_key, filter_by_tag): 179 | 180 | server = Vultr.normalize_result(server, SCHEMA) 181 | 182 | self.inventory.add_host(host=server['name'], group='vultr') 183 | 184 | for attribute, value in server.items(): 185 | self.inventory.set_variable(server['name'], attribute, value) 186 | 187 | if hostname_preference != 'name': 188 | self.inventory.set_variable(server['name'], 'ansible_host', server[hostname_preference]) 189 | 190 | # Use constructed if applicable 191 | strict = self.get_option('strict') 192 | 193 | # Composed variables 194 | self._set_composite_vars(self.get_option('compose'), server, server['name'], strict=strict) 195 | 196 | # Complex groups based on jinja2 conditionals, hosts that meet the conditional are added to group 197 | self._add_host_to_composed_groups(self.get_option('groups'), server, server['name'], strict=strict) 198 | 199 | # Create groups based on variable values and add the corresponding hosts to it 200 | self._add_host_to_keyed_groups(self.get_option('keyed_groups'), server, server['name'], strict=strict) 201 | -------------------------------------------------------------------------------- /plugins/modules/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngine-io/ansible-collection-vultr/81d1926818d1a9e0d5e485d73797c0f951395581/plugins/modules/__init__.py -------------------------------------------------------------------------------- /plugins/modules/vultr_account_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2019, René Moser 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = r''' 12 | --- 13 | module: vultr_account_info 14 | short_description: Get information about the Vultr account. 15 | description: 16 | - Get infos about account balance, charges and payments. 17 | version_added: "0.1.0" 18 | author: "René Moser (@resmo)" 19 | extends_documentation_fragment: 20 | - ngine_io.vultr.vultr 21 | 22 | ''' 23 | 24 | EXAMPLES = r''' 25 | - name: Get Vultr account infos 26 | ngine_io.vultr.vultr_account_info: 27 | register: result 28 | 29 | - name: Print the infos 30 | debug: 31 | var: result.vultr_account_info 32 | ''' 33 | 34 | RETURN = r''' 35 | --- 36 | vultr_api: 37 | description: Response from Vultr API with a few additions/modification 38 | returned: success 39 | type: complex 40 | contains: 41 | api_account: 42 | description: Account used in the ini file to select the key 43 | returned: success 44 | type: str 45 | sample: default 46 | api_timeout: 47 | description: Timeout used for the API requests 48 | returned: success 49 | type: int 50 | sample: 60 51 | api_retries: 52 | description: Amount of max retries for the API requests 53 | returned: success 54 | type: int 55 | sample: 5 56 | api_retry_max_delay: 57 | description: Exponential backoff delay in seconds between retries up to this max delay value. 58 | returned: success 59 | type: int 60 | sample: 12 61 | api_endpoint: 62 | description: Endpoint used for the API requests 63 | returned: success 64 | type: str 65 | sample: "https://api.vultr.com" 66 | vultr_account_info: 67 | description: Response from Vultr API 68 | returned: success 69 | type: complex 70 | contains: 71 | balance: 72 | description: Your account balance. 73 | returned: success 74 | type: float 75 | sample: -214.69 76 | pending_charges: 77 | description: Charges pending. 78 | returned: success 79 | type: float 80 | sample: 57.03 81 | last_payment_date: 82 | description: Date of the last payment. 83 | returned: success 84 | type: str 85 | sample: "2017-08-26 12:47:48" 86 | last_payment_amount: 87 | description: The amount of the last payment transaction. 88 | returned: success 89 | type: float 90 | sample: -250.0 91 | ''' 92 | 93 | from ansible.module_utils.basic import AnsibleModule 94 | from ..module_utils.vultr import ( 95 | Vultr, 96 | vultr_argument_spec, 97 | ) 98 | 99 | 100 | class AnsibleVultrAccountInfo(Vultr): 101 | 102 | def __init__(self, module): 103 | super(AnsibleVultrAccountInfo, self).__init__(module, "vultr_account_info") 104 | 105 | self.returns = { 106 | 'balance': dict(convert_to='float'), 107 | 'pending_charges': dict(convert_to='float'), 108 | 'last_payment_date': dict(), 109 | 'last_payment_amount': dict(convert_to='float'), 110 | } 111 | 112 | def get_account_info(self): 113 | return self.api_query(path="/v1/account/info") 114 | 115 | 116 | def main(): 117 | argument_spec = vultr_argument_spec() 118 | 119 | module = AnsibleModule( 120 | argument_spec=argument_spec, 121 | supports_check_mode=True, 122 | ) 123 | 124 | account_info = AnsibleVultrAccountInfo(module) 125 | result = account_info.get_result(account_info.get_account_info()) 126 | module.exit_json(**result) 127 | 128 | 129 | if __name__ == '__main__': 130 | main() 131 | -------------------------------------------------------------------------------- /plugins/modules/vultr_block_storage_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # Copyright (c) 2019, René Moser 6 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | 12 | DOCUMENTATION = r''' 13 | --- 14 | module: vultr_block_storage_info 15 | short_description: Get information about the Vultr block storage volumes available. 16 | description: 17 | - Get infos about block storage volumes available in Vultr. 18 | version_added: "0.1.0" 19 | author: 20 | - "Yanis Guenane (@Spredzy)" 21 | - "René Moser (@resmo)" 22 | extends_documentation_fragment: 23 | - ngine_io.vultr.vultr 24 | 25 | ''' 26 | 27 | EXAMPLES = r''' 28 | - name: Get Vultr block storage infos 29 | ngine_io.vultr.vultr_block_storage_info: 30 | register: result 31 | 32 | - name: Print the infos 33 | debug: 34 | var: result.vultr_block_storage_info 35 | ''' 36 | 37 | RETURN = r''' 38 | --- 39 | vultr_api: 40 | description: Response from Vultr API with a few additions/modification 41 | returned: success 42 | type: complex 43 | contains: 44 | api_account: 45 | description: Account used in the ini file to select the key 46 | returned: success 47 | type: str 48 | sample: default 49 | api_timeout: 50 | description: Timeout used for the API requests 51 | returned: success 52 | type: int 53 | sample: 60 54 | api_retries: 55 | description: Amount of max retries for the API requests 56 | returned: success 57 | type: int 58 | sample: 5 59 | api_retry_max_delay: 60 | description: Exponential backoff delay in seconds between retries up to this max delay value. 61 | returned: success 62 | type: int 63 | sample: 12 64 | api_endpoint: 65 | description: Endpoint used for the API requests 66 | returned: success 67 | type: str 68 | sample: "https://api.vultr.com" 69 | vultr_block_storage_info: 70 | description: Response from Vultr API as list 71 | returned: success 72 | type: complex 73 | contains: 74 | id: 75 | description: ID of the block storage. 76 | returned: success 77 | type: int 78 | sample: 17332323 79 | size: 80 | description: Size in GB of the block storage. 81 | returned: success 82 | type: int 83 | sample: 10 84 | region: 85 | description: Region the block storage is located in. 86 | returned: success 87 | type: str 88 | sample: New Jersey 89 | name: 90 | description: Name of the block storage. 91 | returned: success 92 | type: str 93 | sample: my volume 94 | cost_per_month: 95 | description: Cost per month of the block storage. 96 | returned: success 97 | type: float 98 | sample: 1.0 99 | date_created: 100 | description: Date created of the block storage. 101 | returned: success 102 | type: str 103 | sample: "2018-07-24 12:59:59" 104 | status: 105 | description: Status of the block storage. 106 | returned: success 107 | type: str 108 | sample: active 109 | attached_to_id: 110 | description: Block storage is attached to this server ID. 111 | returned: success 112 | type: str 113 | sample: null 114 | ''' 115 | 116 | from ansible.module_utils.basic import AnsibleModule 117 | from ..module_utils.vultr import ( 118 | Vultr, 119 | vultr_argument_spec, 120 | ) 121 | 122 | 123 | class AnsibleVultrBlockStorageFacts(Vultr): 124 | 125 | def __init__(self, module): 126 | super(AnsibleVultrBlockStorageFacts, self).__init__(module, "vultr_block_storage_info") 127 | 128 | self.returns = { 129 | 'attached_to_SUBID': dict(key='attached_to_id'), 130 | 'cost_per_month': dict(convert_to='float'), 131 | 'date_created': dict(), 132 | 'SUBID': dict(key='id'), 133 | 'label': dict(key='name'), 134 | 'DCID': dict(key='region', transform=self._get_region_name), 135 | 'size_gb': dict(key='size', convert_to='int'), 136 | 'status': dict() 137 | } 138 | 139 | def _get_region_name(self, region): 140 | return self.get_region(region, 'DCID').get('name') 141 | 142 | def get_block_storage_volumes(self): 143 | return self.api_query(path="/v1/block/list") 144 | 145 | 146 | def main(): 147 | argument_spec = vultr_argument_spec() 148 | 149 | module = AnsibleModule( 150 | argument_spec=argument_spec, 151 | supports_check_mode=True, 152 | ) 153 | 154 | volume_info = AnsibleVultrBlockStorageFacts(module) 155 | result = volume_info.get_result(volume_info.get_block_storage_volumes()) 156 | module.exit_json(**result) 157 | 158 | 159 | if __name__ == '__main__': 160 | main() 161 | -------------------------------------------------------------------------------- /plugins/modules/vultr_dns_domain.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2017, René Moser 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import absolute_import, division, print_function 8 | 9 | __metaclass__ = type 10 | 11 | 12 | DOCUMENTATION = r''' 13 | --- 14 | module: vultr_dns_domain 15 | short_description: Manages DNS domains on Vultr. 16 | description: 17 | - Create and remove DNS domains. 18 | version_added: "0.1.0" 19 | author: "René Moser (@resmo)" 20 | options: 21 | name: 22 | description: 23 | - The domain name. 24 | required: true 25 | aliases: [ domain ] 26 | type: str 27 | server_ip: 28 | description: 29 | - The default server IP. 30 | - Use M(ngine_io.vultr.vultr_dns_record) to change it once the domain is created. 31 | - Required if C(state=present). 32 | type: str 33 | state: 34 | description: 35 | - State of the DNS domain. 36 | default: present 37 | choices: [ present, absent ] 38 | type: str 39 | extends_documentation_fragment: 40 | - ngine_io.vultr.vultr 41 | 42 | ''' 43 | 44 | EXAMPLES = r''' 45 | - name: Ensure a domain exists 46 | ngine_io.vultr.vultr_dns_domain: 47 | name: example.com 48 | server_ip: 10.10.10.10 49 | 50 | - name: Ensure a domain is absent 51 | ngine_io.vultr.vultr_dns_domain: 52 | name: example.com 53 | state: absent 54 | ''' 55 | 56 | RETURN = r''' 57 | --- 58 | vultr_api: 59 | description: Response from Vultr API with a few additions/modification 60 | returned: success 61 | type: complex 62 | contains: 63 | api_account: 64 | description: Account used in the ini file to select the key 65 | returned: success 66 | type: str 67 | sample: default 68 | api_timeout: 69 | description: Timeout used for the API requests 70 | returned: success 71 | type: int 72 | sample: 60 73 | api_retries: 74 | description: Amount of max retries for the API requests 75 | returned: success 76 | type: int 77 | sample: 5 78 | api_retry_max_delay: 79 | description: Exponential backoff delay in seconds between retries up to this max delay value. 80 | returned: success 81 | type: int 82 | sample: 12 83 | api_endpoint: 84 | description: Endpoint used for the API requests 85 | returned: success 86 | type: str 87 | sample: "https://api.vultr.com" 88 | vultr_dns_domain: 89 | description: Response from Vultr API 90 | returned: success 91 | type: complex 92 | contains: 93 | name: 94 | description: Name of the DNS Domain. 95 | returned: success 96 | type: str 97 | sample: example.com 98 | date_created: 99 | description: Date the DNS domain was created. 100 | returned: success 101 | type: str 102 | sample: "2017-08-26 12:47:48" 103 | ''' 104 | 105 | from ansible.module_utils.basic import AnsibleModule 106 | 107 | from ..module_utils.vultr import Vultr, vultr_argument_spec 108 | 109 | 110 | class AnsibleVultrDnsDomain(Vultr): 111 | 112 | def __init__(self, module): 113 | super(AnsibleVultrDnsDomain, self).__init__(module, "vultr_dns_domain") 114 | 115 | self.returns = { 116 | 'domain': dict(key='name'), 117 | 'date_created': dict(), 118 | } 119 | 120 | def get_domain(self): 121 | domains = self.api_query(path="/v1/dns/list") 122 | name = self.module.params.get('name').lower() 123 | if domains: 124 | for domain in domains: 125 | if domain.get('domain').lower() == name: 126 | return domain 127 | return {} 128 | 129 | def present_domain(self): 130 | domain = self.get_domain() 131 | if not domain: 132 | domain = self._create_domain(domain) 133 | return domain 134 | 135 | def _create_domain(self, domain): 136 | self.result['changed'] = True 137 | data = { 138 | 'domain': self.module.params.get('name'), 139 | 'serverip': self.module.params.get('server_ip'), 140 | } 141 | self.result['diff']['before'] = {} 142 | self.result['diff']['after'] = data 143 | 144 | if not self.module.check_mode: 145 | self.api_query( 146 | path="/v1/dns/create_domain", 147 | method="POST", 148 | data=data 149 | ) 150 | domain = self.get_domain() 151 | return domain 152 | 153 | def absent_domain(self): 154 | domain = self.get_domain() 155 | if domain: 156 | self.result['changed'] = True 157 | 158 | data = { 159 | 'domain': domain['domain'], 160 | } 161 | 162 | self.result['diff']['before'] = domain 163 | self.result['diff']['after'] = {} 164 | 165 | if not self.module.check_mode: 166 | self.api_query( 167 | path="/v1/dns/delete_domain", 168 | method="POST", 169 | data=data 170 | ) 171 | return domain 172 | 173 | 174 | def main(): 175 | argument_spec = vultr_argument_spec() 176 | argument_spec.update(dict( 177 | name=dict(type='str', required=True, aliases=['domain']), 178 | server_ip=dict(type='str',), 179 | state=dict(type='str', choices=['present', 'absent'], default='present'), 180 | )) 181 | 182 | module = AnsibleModule( 183 | argument_spec=argument_spec, 184 | required_if=[ 185 | ('state', 'present', ['server_ip']), 186 | ], 187 | supports_check_mode=True, 188 | ) 189 | 190 | vultr_domain = AnsibleVultrDnsDomain(module) 191 | if module.params.get('state') == "absent": 192 | domain = vultr_domain.absent_domain() 193 | else: 194 | domain = vultr_domain.present_domain() 195 | 196 | result = vultr_domain.get_result(domain) 197 | module.exit_json(**result) 198 | 199 | 200 | if __name__ == '__main__': 201 | main() 202 | -------------------------------------------------------------------------------- /plugins/modules/vultr_dns_domain_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright (c) 2018, Yanis Guenane 4 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 | 6 | from __future__ import (absolute_import, division, print_function) 7 | __metaclass__ = type 8 | 9 | 10 | DOCUMENTATION = r''' 11 | --- 12 | module: vultr_dns_domain_info 13 | short_description: Gather information about the Vultr DNS domains available. 14 | description: 15 | - Gather information about DNS domains available in Vultr. 16 | version_added: "0.1.0" 17 | author: "Yanis Guenane (@Spredzy)" 18 | extends_documentation_fragment: 19 | - ngine_io.vultr.vultr 20 | 21 | ''' 22 | 23 | EXAMPLES = r''' 24 | - name: Gather Vultr DNS domains information 25 | ngine_io.vultr.vultr_dns_domains_info: 26 | register: result 27 | 28 | - name: Print the gathered information 29 | debug: 30 | var: result.vultr_dns_domain_info 31 | ''' 32 | 33 | RETURN = r''' 34 | --- 35 | vultr_api: 36 | description: Response from Vultr API with a few additions/modification 37 | returned: success 38 | type: complex 39 | contains: 40 | api_account: 41 | description: Account used in the ini file to select the key 42 | returned: success 43 | type: str 44 | sample: default 45 | api_timeout: 46 | description: Timeout used for the API requests 47 | returned: success 48 | type: int 49 | sample: 60 50 | api_retries: 51 | description: Amount of max retries for the API requests 52 | returned: success 53 | type: int 54 | sample: 5 55 | api_retry_max_delay: 56 | description: Exponential backoff delay in seconds between retries up to this max delay value. 57 | returned: success 58 | type: int 59 | sample: 12 60 | api_endpoint: 61 | description: Endpoint used for the API requests 62 | returned: success 63 | type: str 64 | sample: "https://api.vultr.com" 65 | vultr_dns_domain_info: 66 | description: Response from Vultr API 67 | returned: success 68 | type: complex 69 | contains: 70 | domain: 71 | description: Name of the DNS Domain. 72 | returned: success 73 | type: str 74 | sample: example.com 75 | date_created: 76 | description: Date the DNS domain was created. 77 | returned: success 78 | type: str 79 | sample: "2017-08-26 12:47:48" 80 | ''' 81 | 82 | from ansible.module_utils.basic import AnsibleModule 83 | from ..module_utils.vultr import ( 84 | Vultr, 85 | vultr_argument_spec, 86 | ) 87 | 88 | 89 | class AnsibleVultrDnsDomainInfo(Vultr): 90 | 91 | def __init__(self, module): 92 | super(AnsibleVultrDnsDomainInfo, self).__init__(module, "vultr_dns_domain_info") 93 | 94 | self.returns = { 95 | "date_created": dict(), 96 | "domain": dict(), 97 | } 98 | 99 | def get_domains(self): 100 | return self.api_query(path="/v1/dns/list") 101 | 102 | 103 | def main(): 104 | argument_spec = vultr_argument_spec() 105 | 106 | module = AnsibleModule( 107 | argument_spec=argument_spec, 108 | supports_check_mode=True, 109 | ) 110 | 111 | domain_info = AnsibleVultrDnsDomainInfo(module) 112 | result = domain_info.get_result(domain_info.get_domains()) 113 | module.exit_json(**result) 114 | 115 | 116 | if __name__ == '__main__': 117 | main() 118 | -------------------------------------------------------------------------------- /plugins/modules/vultr_firewall_group.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2017, René Moser 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = ''' 12 | --- 13 | module: vultr_firewall_group 14 | short_description: Manages firewall groups on Vultr. 15 | description: 16 | - Create and remove firewall groups. 17 | version_added: "0.1.0" 18 | author: "René Moser (@resmo)" 19 | options: 20 | name: 21 | description: 22 | - Name of the firewall group. 23 | required: true 24 | aliases: [ description ] 25 | type: str 26 | state: 27 | description: 28 | - State of the firewall group. 29 | default: present 30 | choices: [ present, absent ] 31 | type: str 32 | extends_documentation_fragment: 33 | - ngine_io.vultr.vultr 34 | 35 | ''' 36 | 37 | EXAMPLES = ''' 38 | - name: ensure a firewall group is present 39 | ngine_io.vultr.vultr_firewall_group: 40 | name: my http firewall 41 | 42 | - name: ensure a firewall group is absent 43 | ngine_io.vultr.vultr_firewall_group: 44 | name: my http firewall 45 | state: absent 46 | ''' 47 | 48 | RETURN = ''' 49 | --- 50 | vultr_api: 51 | description: Response from Vultr API with a few additions/modification 52 | returned: success 53 | type: complex 54 | contains: 55 | api_account: 56 | description: Account used in the ini file to select the key 57 | returned: success 58 | type: str 59 | sample: default 60 | api_timeout: 61 | description: Timeout used for the API requests 62 | returned: success 63 | type: int 64 | sample: 60 65 | api_retries: 66 | description: Amount of max retries for the API requests 67 | returned: success 68 | type: int 69 | sample: 5 70 | api_retry_max_delay: 71 | description: Exponential backoff delay in seconds between retries up to this max delay value. 72 | returned: success 73 | type: int 74 | sample: 12 75 | api_endpoint: 76 | description: Endpoint used for the API requests 77 | returned: success 78 | type: str 79 | sample: "https://api.vultr.com" 80 | vultr_firewall_group: 81 | description: Response from Vultr API 82 | returned: success 83 | type: complex 84 | contains: 85 | id: 86 | description: ID of the firewall group 87 | returned: success 88 | type: str 89 | sample: 1234abcd 90 | name: 91 | description: Name of the firewall group 92 | returned: success 93 | type: str 94 | sample: my firewall group 95 | date_created: 96 | description: Date the firewall group was created 97 | returned: success 98 | type: str 99 | sample: "2017-08-26 12:47:48" 100 | date_modified: 101 | description: Date the firewall group was modified 102 | returned: success 103 | type: str 104 | sample: "2017-08-26 12:47:48" 105 | ''' 106 | 107 | from ansible.module_utils.basic import AnsibleModule 108 | from ..module_utils.vultr import ( 109 | Vultr, 110 | vultr_argument_spec, 111 | ) 112 | 113 | 114 | class AnsibleVultrFirewallGroup(Vultr): 115 | 116 | def __init__(self, module): 117 | super(AnsibleVultrFirewallGroup, self).__init__(module, "vultr_firewall_group") 118 | 119 | self.returns = { 120 | 'FIREWALLGROUPID': dict(key='id'), 121 | 'description': dict(key='name'), 122 | 'date_created': dict(), 123 | 'date_modified': dict(), 124 | } 125 | 126 | def get_firewall_group(self): 127 | firewall_groups = self.api_query(path="/v1/firewall/group_list") 128 | if firewall_groups: 129 | for firewall_group_id, firewall_group_data in firewall_groups.items(): 130 | if firewall_group_data.get('description') == self.module.params.get('name'): 131 | return firewall_group_data 132 | return {} 133 | 134 | def present_firewall_group(self): 135 | firewall_group = self.get_firewall_group() 136 | if not firewall_group: 137 | firewall_group = self._create_firewall_group(firewall_group) 138 | return firewall_group 139 | 140 | def _create_firewall_group(self, firewall_group): 141 | self.result['changed'] = True 142 | data = { 143 | 'description': self.module.params.get('name'), 144 | } 145 | self.result['diff']['before'] = {} 146 | self.result['diff']['after'] = data 147 | 148 | if not self.module.check_mode: 149 | self.api_query( 150 | path="/v1/firewall/group_create", 151 | method="POST", 152 | data=data 153 | ) 154 | firewall_group = self.get_firewall_group() 155 | return firewall_group 156 | 157 | def absent_firewall_group(self): 158 | firewall_group = self.get_firewall_group() 159 | if firewall_group: 160 | self.result['changed'] = True 161 | 162 | data = { 163 | 'FIREWALLGROUPID': firewall_group['FIREWALLGROUPID'], 164 | } 165 | 166 | self.result['diff']['before'] = firewall_group 167 | self.result['diff']['after'] = {} 168 | 169 | if not self.module.check_mode: 170 | self.api_query( 171 | path="/v1/firewall/group_delete", 172 | method="POST", 173 | data=data 174 | ) 175 | return firewall_group 176 | 177 | 178 | def main(): 179 | argument_spec = vultr_argument_spec() 180 | argument_spec.update(dict( 181 | name=dict(type='str', required=True, aliases=['description']), 182 | state=dict(type='str', choices=['present', 'absent'], default='present'), 183 | )) 184 | 185 | module = AnsibleModule( 186 | argument_spec=argument_spec, 187 | supports_check_mode=True, 188 | ) 189 | 190 | vultr_firewall_group = AnsibleVultrFirewallGroup(module) 191 | if module.params.get('state') == "absent": 192 | firewall_group = vultr_firewall_group.absent_firewall_group() 193 | else: 194 | firewall_group = vultr_firewall_group.present_firewall_group() 195 | 196 | result = vultr_firewall_group.get_result(firewall_group) 197 | module.exit_json(**result) 198 | 199 | 200 | if __name__ == '__main__': 201 | main() 202 | -------------------------------------------------------------------------------- /plugins/modules/vultr_firewall_group_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright (c) 2018, Yanis Guenane 4 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 | 6 | from __future__ import (absolute_import, division, print_function) 7 | __metaclass__ = type 8 | 9 | 10 | DOCUMENTATION = r''' 11 | --- 12 | module: vultr_firewall_group_info 13 | short_description: Gather information about the Vultr firewall groups available. 14 | description: 15 | - Gather information about firewall groups available in Vultr. 16 | version_added: "0.1.0" 17 | author: "Yanis Guenane (@Spredzy)" 18 | extends_documentation_fragment: 19 | - ngine_io.vultr.vultr 20 | 21 | ''' 22 | 23 | EXAMPLES = r''' 24 | - name: Gather Vultr firewall groups information 25 | ngine_io.vultr.vultr_firewall_group_info: 26 | register: result 27 | 28 | - name: Print the gathered information 29 | debug: 30 | var: result.vultr_firewall_group_info 31 | ''' 32 | 33 | RETURN = r''' 34 | --- 35 | vultr_api: 36 | description: Response from Vultr API with a few additions/modification 37 | returned: success 38 | type: complex 39 | contains: 40 | api_account: 41 | description: Account used in the ini file to select the key 42 | returned: success 43 | type: str 44 | sample: default 45 | api_timeout: 46 | description: Timeout used for the API requests 47 | returned: success 48 | type: int 49 | sample: 60 50 | api_retries: 51 | description: Amount of max retries for the API requests 52 | returned: success 53 | type: int 54 | sample: 5 55 | api_retry_max_delay: 56 | description: Exponential backoff delay in seconds between retries up to this max delay value. 57 | returned: success 58 | type: int 59 | sample: 12 60 | api_endpoint: 61 | description: Endpoint used for the API requests 62 | returned: success 63 | type: str 64 | sample: "https://api.vultr.com" 65 | vultr_firewall_group_info: 66 | description: Response from Vultr API 67 | returned: success 68 | type: complex 69 | contains: 70 | id: 71 | description: ID of the firewall group 72 | returned: success 73 | type: str 74 | sample: 1234abcd 75 | description: 76 | description: Name of the firewall group 77 | returned: success 78 | type: str 79 | sample: my firewall group 80 | date_created: 81 | description: Date the firewall group was created 82 | returned: success 83 | type: str 84 | sample: "2017-08-26 12:47:48" 85 | date_modified: 86 | description: Date the firewall group was modified 87 | returned: success 88 | type: str 89 | sample: "2017-08-26 12:47:48" 90 | ''' 91 | 92 | from ansible.module_utils.basic import AnsibleModule 93 | from ..module_utils.vultr import ( 94 | Vultr, 95 | vultr_argument_spec, 96 | ) 97 | 98 | 99 | class AnsibleVultrFirewallGroupInfo(Vultr): 100 | 101 | def __init__(self, module): 102 | super(AnsibleVultrFirewallGroupInfo, self).__init__(module, "vultr_firewall_group_info") 103 | 104 | self.returns = { 105 | "FIREWALLGROUPID": dict(key='id'), 106 | "date_created": dict(), 107 | "date_modified": dict(), 108 | "description": dict(), 109 | "instance_count": dict(convert_to='int'), 110 | "max_rule_count": dict(convert_to='int'), 111 | "rule_count": dict(convert_to='int') 112 | } 113 | 114 | def get_firewall_group(self): 115 | return self.api_query(path="/v1/firewall/group_list") 116 | 117 | 118 | def parse_fw_group_list(fwgroups_list): 119 | if not fwgroups_list: 120 | return [] 121 | 122 | return [group for id, group in fwgroups_list.items()] 123 | 124 | 125 | def main(): 126 | argument_spec = vultr_argument_spec() 127 | 128 | module = AnsibleModule( 129 | argument_spec=argument_spec, 130 | supports_check_mode=True, 131 | ) 132 | 133 | fw_group_info = AnsibleVultrFirewallGroupInfo(module) 134 | result = fw_group_info.get_result(parse_fw_group_list(fw_group_info.get_firewall_group())) 135 | module.exit_json(**result) 136 | 137 | 138 | if __name__ == '__main__': 139 | main() 140 | -------------------------------------------------------------------------------- /plugins/modules/vultr_network.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = ''' 12 | --- 13 | module: vultr_network 14 | short_description: Manages networks on Vultr. 15 | description: 16 | - Manage networks on Vultr. A network cannot be updated. It needs to be deleted and re-created. 17 | version_added: "0.1.0" 18 | author: "Yanis Guenane (@Spredzy)" 19 | options: 20 | name: 21 | description: 22 | - Name of the network. 23 | required: true 24 | aliases: [ description, label ] 25 | type: str 26 | cidr: 27 | description: 28 | - The CIDR IPv4 network block to be used when attaching servers to this network. Required if I(state=present). 29 | type: str 30 | region: 31 | description: 32 | - Region the network is deployed into. Required if I(state=present). 33 | type: str 34 | state: 35 | description: 36 | - State of the network. 37 | default: present 38 | choices: [ present, absent ] 39 | type: str 40 | extends_documentation_fragment: 41 | - ngine_io.vultr.vultr 42 | 43 | ''' 44 | 45 | EXAMPLES = ''' 46 | - name: Ensure a network is present 47 | ngine_io.vultr.vultr_network: 48 | name: mynet 49 | cidr: 192.168.42.0/24 50 | region: Amsterdam 51 | 52 | - name: Ensure a network is absent 53 | ngine_io.vultr.vultr_network: 54 | name: mynet 55 | state: absent 56 | ''' 57 | 58 | RETURN = ''' 59 | --- 60 | vultr_api: 61 | description: Response from Vultr API with a few additions/modification 62 | returned: success 63 | type: complex 64 | contains: 65 | api_account: 66 | description: Account used in the ini file to select the key 67 | returned: success 68 | type: str 69 | sample: default 70 | api_timeout: 71 | description: Timeout used for the API requests 72 | returned: success 73 | type: int 74 | sample: 60 75 | api_retries: 76 | description: Amount of max retries for the API requests 77 | returned: success 78 | type: int 79 | sample: 5 80 | api_retry_max_delay: 81 | description: Exponential backoff delay in seconds between retries up to this max delay value. 82 | returned: success 83 | type: int 84 | sample: 12 85 | api_endpoint: 86 | description: Endpoint used for the API requests 87 | returned: success 88 | type: str 89 | sample: "https://api.vultr.com" 90 | vultr_network: 91 | description: Response from Vultr API 92 | returned: success 93 | type: complex 94 | contains: 95 | id: 96 | description: ID of the network 97 | returned: success 98 | type: str 99 | sample: "net5b62c6dc63ef5" 100 | name: 101 | description: Name (label) of the network 102 | returned: success 103 | type: str 104 | sample: "mynetwork" 105 | date_created: 106 | description: Date when the network was created 107 | returned: success 108 | type: str 109 | sample: "2018-08-02 08:54:52" 110 | region: 111 | description: Region the network was deployed into 112 | returned: success 113 | type: str 114 | sample: "Amsterdam" 115 | v4_subnet: 116 | description: IPv4 Network address 117 | returned: success 118 | type: str 119 | sample: "192.168.42.0" 120 | v4_subnet_mask: 121 | description: Ipv4 Network mask 122 | returned: success 123 | type: int 124 | sample: 24 125 | ''' 126 | 127 | from ansible.module_utils.basic import AnsibleModule 128 | from ..module_utils.vultr import ( 129 | Vultr, 130 | vultr_argument_spec, 131 | ) 132 | 133 | 134 | class AnsibleVultrNetwork(Vultr): 135 | 136 | def __init__(self, module): 137 | super(AnsibleVultrNetwork, self).__init__(module, "vultr_network") 138 | 139 | self.returns = { 140 | 'NETWORKID': dict(key='id'), 141 | 'DCID': dict(key='region', transform=self._get_region_name), 142 | 'date_created': dict(), 143 | 'description': dict(key='name'), 144 | 'v4_subnet': dict(), 145 | 'v4_subnet_mask': dict(convert_to='int'), 146 | } 147 | 148 | def _get_region_name(self, region_id=None): 149 | return self.get_region().get('name') 150 | 151 | def get_network(self): 152 | networks = self.api_query(path="/v1/network/list") 153 | if networks: 154 | for id, network in networks.items(): 155 | if network.get('description') == self.module.params.get('name'): 156 | return network 157 | return {} 158 | 159 | def present_network(self): 160 | network = self.get_network() 161 | if not network: 162 | network = self._create_network(network) 163 | return network 164 | 165 | def _create_network(self, network): 166 | self.result['changed'] = True 167 | data = { 168 | 'description': self.module.params.get('name'), 169 | 'DCID': self.get_region()['DCID'], 170 | 'v4_subnet': self.module.params.get('cidr').split('/')[0], 171 | 'v4_subnet_mask': self.module.params.get('cidr').split('/')[1] 172 | } 173 | self.result['diff']['before'] = {} 174 | self.result['diff']['after'] = data 175 | 176 | if not self.module.check_mode: 177 | self.api_query( 178 | path="/v1/network/create", 179 | method="POST", 180 | data=data 181 | ) 182 | network = self.get_network() 183 | return network 184 | 185 | def absent_network(self): 186 | network = self.get_network() 187 | if network: 188 | self.result['changed'] = True 189 | 190 | data = { 191 | 'NETWORKID': network['NETWORKID'], 192 | } 193 | 194 | self.result['diff']['before'] = network 195 | self.result['diff']['after'] = {} 196 | 197 | if not self.module.check_mode: 198 | self.api_query( 199 | path="/v1/network/destroy", 200 | method="POST", 201 | data=data 202 | ) 203 | return network 204 | 205 | 206 | def main(): 207 | argument_spec = vultr_argument_spec() 208 | argument_spec.update(dict( 209 | name=dict(type='str', required=True, aliases=['description', 'label']), 210 | cidr=dict(type='str',), 211 | region=dict(type='str',), 212 | state=dict(choices=['present', 'absent'], default='present'), 213 | )) 214 | 215 | module = AnsibleModule( 216 | argument_spec=argument_spec, 217 | supports_check_mode=True, 218 | required_if=[['state', 'present', ['cidr', 'region']]] 219 | ) 220 | 221 | vultr_network = AnsibleVultrNetwork(module) 222 | if module.params.get('state') == "absent": 223 | network = vultr_network.absent_network() 224 | else: 225 | network = vultr_network.present_network() 226 | 227 | result = vultr_network.get_result(network) 228 | module.exit_json(**result) 229 | 230 | 231 | if __name__ == '__main__': 232 | main() 233 | -------------------------------------------------------------------------------- /plugins/modules/vultr_network_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # 3 | # Copyright (c) 2018, Yanis Guenane 4 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 | 6 | from __future__ import (absolute_import, division, print_function) 7 | __metaclass__ = type 8 | 9 | 10 | DOCUMENTATION = r''' 11 | --- 12 | module: vultr_network_info 13 | short_description: Gather information about the Vultr networks available. 14 | description: 15 | - Gather information about networks available in Vultr. 16 | version_added: "0.1.0" 17 | author: "Yanis Guenane (@Spredzy)" 18 | extends_documentation_fragment: 19 | - ngine_io.vultr.vultr 20 | 21 | ''' 22 | 23 | EXAMPLES = r''' 24 | - name: Gather Vultr networks information 25 | ngine_io.vultr.vultr_network_info: 26 | register: result 27 | 28 | - name: Print the gathered information 29 | debug: 30 | var: result.vultr_network_info 31 | ''' 32 | 33 | RETURN = r''' 34 | --- 35 | vultr_api: 36 | description: Response from Vultr API with a few additions/modification 37 | returned: success 38 | type: complex 39 | contains: 40 | api_account: 41 | description: Account used in the ini file to select the key 42 | returned: success 43 | type: str 44 | sample: default 45 | api_timeout: 46 | description: Timeout used for the API requests 47 | returned: success 48 | type: int 49 | sample: 60 50 | api_retries: 51 | description: Amount of max retries for the API requests 52 | returned: success 53 | type: int 54 | sample: 5 55 | api_retry_max_delay: 56 | description: Exponential backoff delay in seconds between retries up to this max delay value. 57 | returned: success 58 | type: int 59 | sample: 12 60 | api_endpoint: 61 | description: Endpoint used for the API requests 62 | returned: success 63 | type: str 64 | sample: "https://api.vultr.com" 65 | vultr_network_info: 66 | description: Response from Vultr API 67 | returned: success 68 | type: complex 69 | contains: 70 | id: 71 | description: ID of the network 72 | returned: success 73 | type: str 74 | sample: "net5b62c6dc63ef5" 75 | name: 76 | description: Name (label) of the network 77 | returned: success 78 | type: str 79 | sample: "mynetwork" 80 | date_created: 81 | description: Date when the network was created 82 | returned: success 83 | type: str 84 | sample: "2018-08-02 08:54:52" 85 | region: 86 | description: Region the network was deployed into 87 | returned: success 88 | type: str 89 | sample: "Amsterdam" 90 | v4_subnet: 91 | description: IPv4 Network address 92 | returned: success 93 | type: str 94 | sample: "192.168.42.0" 95 | v4_subnet_mask: 96 | description: Ipv4 Network mask 97 | returned: success 98 | type: int 99 | sample: 24 100 | ''' 101 | 102 | from ansible.module_utils.basic import AnsibleModule 103 | from ..module_utils.vultr import ( 104 | Vultr, 105 | vultr_argument_spec, 106 | ) 107 | 108 | 109 | class AnsibleVultrNetworkInfo(Vultr): 110 | 111 | def __init__(self, module): 112 | super(AnsibleVultrNetworkInfo, self).__init__(module, "vultr_network_info") 113 | 114 | self.returns = { 115 | 'DCID': dict(key='region', transform=self._get_region_name), 116 | 'NETWORKID': dict(key='id'), 117 | 'date_created': dict(), 118 | 'description': dict(key='name'), 119 | 'v4_subnet': dict(), 120 | 'v4_subnet_mask': dict(convert_to='int'), 121 | } 122 | 123 | def _get_region_name(self, region): 124 | return self.query_resource_by_key( 125 | key='DCID', 126 | value=region, 127 | resource='regions', 128 | use_cache=True 129 | )['name'] 130 | 131 | def get_networks(self): 132 | return self.api_query(path="/v1/network/list") 133 | 134 | 135 | def parse_network_list(network_list): 136 | if isinstance(network_list, list): 137 | return [] 138 | 139 | return [network for id, network in network_list.items()] 140 | 141 | 142 | def main(): 143 | argument_spec = vultr_argument_spec() 144 | 145 | module = AnsibleModule( 146 | argument_spec=argument_spec, 147 | supports_check_mode=True, 148 | ) 149 | 150 | network_info = AnsibleVultrNetworkInfo(module) 151 | result = network_info.get_result(parse_network_list(network_info.get_networks())) 152 | module.exit_json(**result) 153 | 154 | 155 | if __name__ == '__main__': 156 | main() 157 | -------------------------------------------------------------------------------- /plugins/modules/vultr_os_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # Copyright (c) 2019, René Moser 6 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | 12 | DOCUMENTATION = r''' 13 | --- 14 | module: vultr_os_info 15 | short_description: Get information about the Vultr OSes available. 16 | description: 17 | - Get infos about OSes available to boot servers. 18 | version_added: "0.1.0" 19 | author: 20 | - "Yanis Guenane (@Spredzy)" 21 | - "René Moser (@resmo)" 22 | extends_documentation_fragment: 23 | - ngine_io.vultr.vultr 24 | 25 | ''' 26 | 27 | EXAMPLES = r''' 28 | - name: Get Vultr OSes infos 29 | ngine_io.vultr.vultr_os_info: 30 | register: results 31 | 32 | - name: Print the gathered infos 33 | debug: 34 | var: results.vultr_os_info 35 | ''' 36 | 37 | RETURN = r''' 38 | --- 39 | vultr_api: 40 | description: Response from Vultr API with a few additions/modification 41 | returned: success 42 | type: complex 43 | contains: 44 | api_account: 45 | description: Account used in the ini file to select the key 46 | returned: success 47 | type: str 48 | sample: default 49 | api_timeout: 50 | description: Timeout used for the API requests 51 | returned: success 52 | type: int 53 | sample: 60 54 | api_retries: 55 | description: Amount of max retries for the API requests 56 | returned: success 57 | type: int 58 | sample: 5 59 | api_retry_max_delay: 60 | description: Exponential backoff delay in seconds between retries up to this max delay value. 61 | returned: success 62 | type: int 63 | sample: 12 64 | api_endpoint: 65 | description: Endpoint used for the API requests 66 | returned: success 67 | type: str 68 | sample: "https://api.vultr.com" 69 | vultr_os_info: 70 | description: Response from Vultr API as list 71 | returned: available 72 | type: complex 73 | contains: 74 | arch: 75 | description: OS Architecture 76 | returned: success 77 | type: str 78 | sample: x64 79 | family: 80 | description: OS family 81 | returned: success 82 | type: str 83 | sample: openbsd 84 | name: 85 | description: OS name 86 | returned: success 87 | type: str 88 | sample: OpenBSD 6 x64 89 | windows: 90 | description: OS is a MS Windows 91 | returned: success 92 | type: bool 93 | ''' 94 | 95 | from ansible.module_utils.basic import AnsibleModule 96 | from ..module_utils.vultr import ( 97 | Vultr, 98 | vultr_argument_spec, 99 | ) 100 | 101 | 102 | class AnsibleVultrOSInfo(Vultr): 103 | 104 | def __init__(self, module): 105 | super(AnsibleVultrOSInfo, self).__init__(module, "vultr_os_info") 106 | 107 | self.returns = { 108 | "OSID": dict(key='id', convert_to='int'), 109 | "arch": dict(), 110 | "family": dict(), 111 | "name": dict(), 112 | "windows": dict(convert_to='bool') 113 | } 114 | 115 | def get_oses(self): 116 | return self.api_query(path="/v1/os/list") 117 | 118 | 119 | def parse_oses_list(oses_list): 120 | return [os for id, os in oses_list.items()] 121 | 122 | 123 | def main(): 124 | argument_spec = vultr_argument_spec() 125 | 126 | module = AnsibleModule( 127 | argument_spec=argument_spec, 128 | supports_check_mode=True, 129 | ) 130 | 131 | os_info = AnsibleVultrOSInfo(module) 132 | result = os_info.get_result(parse_oses_list(os_info.get_oses())) 133 | module.exit_json(**result) 134 | 135 | 136 | if __name__ == '__main__': 137 | main() 138 | -------------------------------------------------------------------------------- /plugins/modules/vultr_plan_baremetal_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # (c) 2018, Yanis Guenane 5 | # (c) 2020, Simon Baerlocher 6 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | DOCUMENTATION = r''' 12 | --- 13 | module: vultr_plan_baremetal_info 14 | short_description: Gather information about the Vultr Bare Metal plans available. 15 | description: 16 | - Gather information about Bare Metal plans available to boot servers. 17 | version_added: "0.3.0" 18 | author: "Simon Baerlocher (@sbaerlocher)" 19 | extends_documentation_fragment: 20 | - ngine_io.vultr.vultr 21 | ''' 22 | 23 | EXAMPLES = r''' 24 | - name: Gather Vultr Bare Metal plans information 25 | ngine_io.vultr.vultr_baremetal_plan_info: 26 | register: result 27 | 28 | - name: Print the gathered information 29 | debug: 30 | var: result.vultr_baremetal_plan_info 31 | ''' 32 | 33 | RETURN = r''' 34 | --- 35 | vultr_api: 36 | description: Response from Vultr API with a few additions/modification 37 | returned: success 38 | type: complex 39 | contains: 40 | api_account: 41 | description: Account used in the ini file to select the key 42 | returned: success 43 | type: str 44 | sample: default 45 | api_timeout: 46 | description: Timeout used for the API requests 47 | returned: success 48 | type: int 49 | sample: 60 50 | api_retries: 51 | description: Amount of max retries for the API requests 52 | returned: success 53 | type: int 54 | sample: 5 55 | api_retry_max_delay: 56 | description: Exponential backoff delay in seconds between retries up to this max delay value. 57 | returned: success 58 | type: int 59 | sample: 12 60 | api_endpoint: 61 | description: Endpoint used for the API requests 62 | returned: success 63 | type: str 64 | sample: "https://api.vultr.com" 65 | vultr_plan_baremetal_info: 66 | description: Response from Vultr API 67 | returned: success 68 | type: complex 69 | contains: 70 | plan: 71 | description: List of the Bare Metal plans available. 72 | returned: success 73 | type: list 74 | sample: [{ 75 | "available_locations": [ 76 | 1 77 | ], 78 | "bandwidth": 40.0, 79 | "bandwidth_gb": 40960, 80 | "disk": 110, 81 | "id": 118, 82 | "name": "32768 MB RAM,110 GB SSD,40.00 TB BW", 83 | "plan_type": "DEDICATED", 84 | "price_per_month": 240.0, 85 | "ram": 32768, 86 | "vcpu_count": 8, 87 | "windows": false 88 | }] 89 | ''' 90 | 91 | from ansible.module_utils.basic import AnsibleModule 92 | from ..module_utils.vultr import ( 93 | Vultr, 94 | vultr_argument_spec, 95 | ) 96 | 97 | 98 | class AnsibleVultrPlanInfo(Vultr): 99 | 100 | def __init__(self, module): 101 | super(AnsibleVultrPlanInfo, self).__init__(module, "vultr_plan_baremetal_info") 102 | 103 | self.returns = { 104 | "METALPLANID": dict(key='id', convert_to='int'), 105 | "available_locations": dict(), 106 | "bandwidth_tb": dict(convert_to='int'), 107 | "disk": dict(), 108 | "name": dict(), 109 | "plan_type": dict(), 110 | "price_per_month": dict(convert_to='float'), 111 | "ram": dict(convert_to='int'), 112 | "windows": dict(convert_to='bool'), 113 | "cpu_count": dict(convert_to='int'), 114 | "cpu_model": dict(), 115 | "cpu_thread_count": dict(convert_to='int'), 116 | } 117 | 118 | def get_plans_baremetal(self): 119 | return self.api_query(path="/v1/plans/list_baremetal") 120 | 121 | 122 | def parse_plans_baremetal_list(plans_baremetal_list): 123 | return [plan_baremetal for id, plan_baremetal in plans_baremetal_list.items()] 124 | 125 | 126 | def main(): 127 | argument_spec = vultr_argument_spec() 128 | 129 | module = AnsibleModule( 130 | argument_spec=argument_spec, 131 | supports_check_mode=True, 132 | ) 133 | 134 | plan_baremetal_info = AnsibleVultrPlanInfo(module) 135 | result = plan_baremetal_info.get_result(parse_plans_baremetal_list(plan_baremetal_info.get_plans_baremetal())) 136 | module.exit_json(**result) 137 | 138 | 139 | if __name__ == '__main__': 140 | main() 141 | -------------------------------------------------------------------------------- /plugins/modules/vultr_plan_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = r''' 12 | --- 13 | module: vultr_plan_info 14 | short_description: Gather information about the Vultr plans available. 15 | description: 16 | - Gather information about plans available to boot servers. 17 | version_added: "0.1.0" 18 | author: "Yanis Guenane (@Spredzy)" 19 | extends_documentation_fragment: 20 | - ngine_io.vultr.vultr 21 | ''' 22 | 23 | EXAMPLES = r''' 24 | - name: Gather Vultr plans information 25 | ngine_io.vultr.vultr_plan_info: 26 | register: result 27 | 28 | - name: Print the gathered information 29 | debug: 30 | var: result.vultr_plan_info 31 | ''' 32 | 33 | RETURN = r''' 34 | --- 35 | vultr_api: 36 | description: Response from Vultr API with a few additions/modification 37 | returned: success 38 | type: complex 39 | contains: 40 | api_account: 41 | description: Account used in the ini file to select the key 42 | returned: success 43 | type: str 44 | sample: default 45 | api_timeout: 46 | description: Timeout used for the API requests 47 | returned: success 48 | type: int 49 | sample: 60 50 | api_retries: 51 | description: Amount of max retries for the API requests 52 | returned: success 53 | type: int 54 | sample: 5 55 | api_retry_max_delay: 56 | description: Exponential backoff delay in seconds between retries up to this max delay value. 57 | returned: success 58 | type: int 59 | sample: 12 60 | api_endpoint: 61 | description: Endpoint used for the API requests 62 | returned: success 63 | type: str 64 | sample: "https://api.vultr.com" 65 | vultr_plan_info: 66 | description: Response from Vultr API 67 | returned: success 68 | type: complex 69 | contains: 70 | plan: 71 | description: List of the plans available. 72 | returned: success 73 | type: list 74 | sample: [{ 75 | "available_locations": [ 76 | 1 77 | ], 78 | "bandwidth": 40.0, 79 | "bandwidth_gb": 40960, 80 | "disk": 110, 81 | "id": 118, 82 | "name": "32768 MB RAM,110 GB SSD,40.00 TB BW", 83 | "plan_type": "DEDICATED", 84 | "price_per_month": 240.0, 85 | "ram": 32768, 86 | "vcpu_count": 8, 87 | "windows": false 88 | }] 89 | ''' 90 | 91 | from ansible.module_utils.basic import AnsibleModule 92 | from ..module_utils.vultr import ( 93 | Vultr, 94 | vultr_argument_spec, 95 | ) 96 | 97 | 98 | class AnsibleVultrPlanInfo(Vultr): 99 | 100 | def __init__(self, module): 101 | super(AnsibleVultrPlanInfo, self).__init__(module, "vultr_plan_info") 102 | 103 | self.returns = { 104 | "VPSPLANID": dict(key='id', convert_to='int'), 105 | "available_locations": dict(), 106 | "bandwidth": dict(convert_to='float'), 107 | "bandwidth_gb": dict(convert_to='int'), 108 | "disk": dict(convert_to='int'), 109 | "name": dict(), 110 | "plan_type": dict(), 111 | "price_per_month": dict(convert_to='float'), 112 | "ram": dict(convert_to='int'), 113 | "vcpu_count": dict(convert_to='int'), 114 | "windows": dict(convert_to='bool') 115 | } 116 | 117 | def get_plans(self): 118 | return self.api_query(path="/v1/plans/list") 119 | 120 | 121 | def parse_plans_list(plans_list): 122 | return [plan for id, plan in plans_list.items()] 123 | 124 | 125 | def main(): 126 | argument_spec = vultr_argument_spec() 127 | 128 | module = AnsibleModule( 129 | argument_spec=argument_spec, 130 | supports_check_mode=True, 131 | ) 132 | 133 | plan_info = AnsibleVultrPlanInfo(module) 134 | result = plan_info.get_result(parse_plans_list(plan_info.get_plans())) 135 | module.exit_json(**result) 136 | 137 | 138 | if __name__ == '__main__': 139 | main() 140 | -------------------------------------------------------------------------------- /plugins/modules/vultr_region_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = r''' 12 | --- 13 | module: vultr_region_info 14 | short_description: Gather information about the Vultr regions available. 15 | description: 16 | - Gather information about regions available to boot servers. 17 | version_added: "0.1.0" 18 | author: "Yanis Guenane (@Spredzy)" 19 | extends_documentation_fragment: 20 | - ngine_io.vultr.vultr 21 | 22 | ''' 23 | 24 | EXAMPLES = r''' 25 | - name: Gather Vultr regions information 26 | ngine_io.vultr.vultr_region_info: 27 | register: result 28 | 29 | - name: Print the gathered information 30 | debug: 31 | var: result.vultr_region_info 32 | ''' 33 | 34 | RETURN = r''' 35 | --- 36 | vultr_api: 37 | description: Response from Vultr API with a few additions/modification 38 | returned: success 39 | type: complex 40 | contains: 41 | api_account: 42 | description: Account used in the ini file to select the key 43 | returned: success 44 | type: str 45 | sample: default 46 | api_timeout: 47 | description: Timeout used for the API requests 48 | returned: success 49 | type: int 50 | sample: 60 51 | api_retries: 52 | description: Amount of max retries for the API requests 53 | returned: success 54 | type: int 55 | sample: 5 56 | api_retry_max_delay: 57 | description: Exponential backoff delay in seconds between retries up to this max delay value. 58 | returned: success 59 | type: int 60 | sample: 12 61 | api_endpoint: 62 | description: Endpoint used for the API requests 63 | returned: success 64 | type: str 65 | sample: "https://api.vultr.com" 66 | vultr_region_info: 67 | description: Response from Vultr API 68 | returned: success 69 | type: list 70 | sample: [ 71 | { 72 | "block_storage": false, 73 | "continent": "Europe", 74 | "country": "GB", 75 | "ddos_protection": true, 76 | "id": 8, 77 | "name": "London", 78 | "regioncode": "LHR", 79 | "state": "" 80 | } 81 | ] 82 | ''' 83 | 84 | from ansible.module_utils.basic import AnsibleModule 85 | from ..module_utils.vultr import ( 86 | Vultr, 87 | vultr_argument_spec, 88 | ) 89 | 90 | 91 | class AnsibleVultrRegionInfo(Vultr): 92 | 93 | def __init__(self, module): 94 | super(AnsibleVultrRegionInfo, self).__init__(module, "vultr_region_info") 95 | 96 | self.returns = { 97 | "DCID": dict(key='id', convert_to='int'), 98 | "block_storage": dict(convert_to='bool'), 99 | "continent": dict(), 100 | "country": dict(), 101 | "ddos_protection": dict(convert_to='bool'), 102 | "name": dict(), 103 | "regioncode": dict(), 104 | "state": dict() 105 | } 106 | 107 | def get_regions(self): 108 | return self.api_query(path="/v1/regions/list") 109 | 110 | 111 | def parse_regions_list(regions_list): 112 | return [region for id, region in regions_list.items()] 113 | 114 | 115 | def main(): 116 | argument_spec = vultr_argument_spec() 117 | 118 | module = AnsibleModule( 119 | argument_spec=argument_spec, 120 | supports_check_mode=True, 121 | ) 122 | 123 | region_info = AnsibleVultrRegionInfo(module) 124 | result = region_info.get_result(parse_regions_list(region_info.get_regions())) 125 | module.exit_json(**result) 126 | 127 | 128 | if __name__ == '__main__': 129 | main() 130 | -------------------------------------------------------------------------------- /plugins/modules/vultr_server_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = r''' 12 | --- 13 | module: vultr_server_info 14 | short_description: Gather information about the Vultr servers available. 15 | description: 16 | - Gather information about servers available. 17 | version_added: "0.1.0" 18 | author: "Yanis Guenane (@Spredzy)" 19 | extends_documentation_fragment: 20 | - ngine_io.vultr.vultr 21 | 22 | ''' 23 | 24 | EXAMPLES = r''' 25 | - name: Gather Vultr servers information 26 | ngine_io.vultr.vultr_server_info: 27 | register: result 28 | 29 | - name: Print the gathered information 30 | debug: 31 | var: result.vultr_server_info 32 | ''' 33 | 34 | RETURN = r''' 35 | --- 36 | vultr_api: 37 | description: Response from Vultr API with a few additions/modification 38 | returned: success 39 | type: complex 40 | contains: 41 | api_account: 42 | description: Account used in the ini file to select the key 43 | returned: success 44 | type: str 45 | sample: default 46 | api_timeout: 47 | description: Timeout used for the API requests 48 | returned: success 49 | type: int 50 | sample: 60 51 | api_retries: 52 | description: Amount of max retries for the API requests 53 | returned: success 54 | type: int 55 | sample: 5 56 | api_retry_max_delay: 57 | description: Exponential backoff delay in seconds between retries up to this max delay value. 58 | returned: success 59 | type: int 60 | sample: 12 61 | api_endpoint: 62 | description: Endpoint used for the API requests 63 | returned: success 64 | type: str 65 | sample: "https://api.vultr.com" 66 | vultr_server_info: 67 | description: Response from Vultr API 68 | returned: success 69 | type: complex 70 | contains: 71 | id: 72 | description: ID of the server 73 | returned: success 74 | type: str 75 | sample: 10194376 76 | name: 77 | description: Name (label) of the server 78 | returned: success 79 | type: str 80 | sample: "ansible-test-vm" 81 | plan: 82 | description: Plan used for the server 83 | returned: success 84 | type: str 85 | sample: "1024 MB RAM,25 GB SSD,1.00 TB BW" 86 | allowed_bandwidth_gb: 87 | description: Allowed bandwidth to use in GB 88 | returned: success 89 | type: float 90 | sample: 1000.5 91 | auto_backup_enabled: 92 | description: Whether automatic backups are enabled 93 | returned: success 94 | type: bool 95 | sample: false 96 | cost_per_month: 97 | description: Cost per month for the server 98 | returned: success 99 | type: float 100 | sample: 5.00 101 | current_bandwidth_gb: 102 | description: Current bandwidth used for the server 103 | returned: success 104 | type: int 105 | sample: 0 106 | date_created: 107 | description: Date when the server was created 108 | returned: success 109 | type: str 110 | sample: "2017-08-26 12:47:48" 111 | default_password: 112 | description: Password to login as root into the server 113 | returned: success 114 | type: str 115 | sample: "!p3EWYJm$qDWYaFr" 116 | disk: 117 | description: Information about the disk 118 | returned: success 119 | type: str 120 | sample: "Virtual 25 GB" 121 | v4_gateway: 122 | description: IPv4 gateway 123 | returned: success 124 | type: str 125 | sample: "45.32.232.1" 126 | internal_ip: 127 | description: Internal IP 128 | returned: success 129 | type: str 130 | sample: "" 131 | kvm_url: 132 | description: URL to the VNC 133 | returned: success 134 | type: str 135 | sample: "https://my.vultr.com/subs/vps/novnc/api.php?data=xyz" 136 | region: 137 | description: Region the server was deployed into 138 | returned: success 139 | type: str 140 | sample: "Amsterdam" 141 | v4_main_ip: 142 | description: Main IPv4 143 | returned: success 144 | type: str 145 | sample: "45.32.233.154" 146 | v4_netmask: 147 | description: Netmask IPv4 148 | returned: success 149 | type: str 150 | sample: "255.255.254.0" 151 | os: 152 | description: Operating system used for the server 153 | returned: success 154 | type: str 155 | sample: "CentOS 6 x64" 156 | firewall_group: 157 | description: Firewall group the server is assigned to 158 | returned: success and available 159 | type: str 160 | sample: "CentOS 6 x64" 161 | pending_charges: 162 | description: Pending charges 163 | returned: success 164 | type: float 165 | sample: 0.01 166 | power_status: 167 | description: Power status of the server 168 | returned: success 169 | type: str 170 | sample: "running" 171 | ram: 172 | description: Information about the RAM size 173 | returned: success 174 | type: str 175 | sample: "1024 MB" 176 | server_state: 177 | description: State about the server 178 | returned: success 179 | type: str 180 | sample: "ok" 181 | status: 182 | description: Status about the deployment of the server 183 | returned: success 184 | type: str 185 | sample: "active" 186 | tag: 187 | description: TBD 188 | returned: success 189 | type: str 190 | sample: "" 191 | v6_main_ip: 192 | description: Main IPv6 193 | returned: success 194 | type: str 195 | sample: "" 196 | v6_network: 197 | description: Network IPv6 198 | returned: success 199 | type: str 200 | sample: "" 201 | v6_network_size: 202 | description: Network size IPv6 203 | returned: success 204 | type: str 205 | sample: "" 206 | v6_networks: 207 | description: Networks IPv6 208 | returned: success 209 | type: list 210 | sample: [] 211 | vcpu_count: 212 | description: Virtual CPU count 213 | returned: success 214 | type: int 215 | sample: 1 216 | ''' 217 | 218 | from ansible.module_utils.basic import AnsibleModule 219 | from ..module_utils.vultr import ( 220 | Vultr, 221 | vultr_argument_spec, 222 | ) 223 | 224 | 225 | class AnsibleVultrServerInfo(Vultr): 226 | 227 | def __init__(self, module): 228 | super(AnsibleVultrServerInfo, self).__init__(module, "vultr_server_info") 229 | 230 | self.returns = { 231 | "APPID": dict(key='application', convert_to='int', transform=self._get_application_name), 232 | "FIREWALLGROUPID": dict(key='firewallgroup', transform=self._get_firewallgroup_name), 233 | "SUBID": dict(key='id', convert_to='int'), 234 | "VPSPLANID": dict(key='plan', convert_to='int', transform=self._get_plan_name), 235 | "allowed_bandwidth_gb": dict(convert_to='float'), 236 | 'auto_backups': dict(key='auto_backup_enabled', convert_to='bool'), 237 | "cost_per_month": dict(convert_to='float'), 238 | "current_bandwidth_gb": dict(convert_to='float'), 239 | "date_created": dict(), 240 | "default_password": dict(), 241 | "disk": dict(), 242 | "gateway_v4": dict(key='v4_gateway'), 243 | "internal_ip": dict(), 244 | "kvm_url": dict(), 245 | "label": dict(key='name'), 246 | "location": dict(key='region'), 247 | "main_ip": dict(key='v4_main_ip'), 248 | "netmask_v4": dict(key='v4_netmask'), 249 | "os": dict(), 250 | "pending_charges": dict(convert_to='float'), 251 | "power_status": dict(), 252 | "ram": dict(), 253 | "server_state": dict(), 254 | "status": dict(), 255 | "tag": dict(), 256 | "v6_main_ip": dict(), 257 | "v6_network": dict(), 258 | "v6_network_size": dict(), 259 | "v6_networks": dict(), 260 | "vcpu_count": dict(convert_to='int'), 261 | } 262 | 263 | def _get_application_name(self, application): 264 | if application == 0: 265 | return None 266 | 267 | return self.get_application(application, 'APPID').get('name') 268 | 269 | def _get_firewallgroup_name(self, firewallgroup): 270 | if firewallgroup == 0: 271 | return None 272 | 273 | return self.get_firewallgroup(firewallgroup, 'FIREWALLGROUPID').get('description') 274 | 275 | def _get_plan_name(self, plan): 276 | return self.get_plan(plan, 'VPSPLANID', optional=True).get('name') or 'N/A' 277 | 278 | def get_servers(self): 279 | return self.api_query(path="/v1/server/list") 280 | 281 | 282 | def parse_servers_list(servers_list): 283 | return [server for id, server in servers_list.items()] 284 | 285 | 286 | def main(): 287 | argument_spec = vultr_argument_spec() 288 | 289 | module = AnsibleModule( 290 | argument_spec=argument_spec, 291 | supports_check_mode=True, 292 | ) 293 | 294 | server_info = AnsibleVultrServerInfo(module) 295 | result = server_info.get_result(parse_servers_list(server_info.get_servers())) 296 | module.exit_json(**result) 297 | 298 | 299 | if __name__ == '__main__': 300 | main() 301 | -------------------------------------------------------------------------------- /plugins/modules/vultr_ssh_key.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2017, René Moser 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = ''' 12 | --- 13 | module: vultr_ssh_key 14 | short_description: Manages ssh keys on Vultr. 15 | description: 16 | - Create, update and remove ssh keys. 17 | version_added: "0.1.0" 18 | author: "René Moser (@resmo)" 19 | options: 20 | name: 21 | description: 22 | - Name of the ssh key. 23 | required: true 24 | type: str 25 | ssh_key: 26 | description: 27 | - SSH public key. 28 | - Required if C(state=present). 29 | type: str 30 | state: 31 | description: 32 | - State of the ssh key. 33 | default: present 34 | choices: [ present, absent ] 35 | type: str 36 | extends_documentation_fragment: 37 | - ngine_io.vultr.vultr 38 | 39 | ''' 40 | 41 | EXAMPLES = ''' 42 | - name: ensure an SSH key is present 43 | ngine_io.vultr.vultr_ssh_key: 44 | name: my ssh key 45 | ssh_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}" 46 | 47 | - name: ensure an SSH key is absent 48 | ngine_io.vultr.vultr_ssh_key: 49 | name: my ssh key 50 | state: absent 51 | ''' 52 | 53 | RETURN = ''' 54 | --- 55 | vultr_api: 56 | description: Response from Vultr API with a few additions/modification 57 | returned: success 58 | type: complex 59 | contains: 60 | api_account: 61 | description: Account used in the ini file to select the key 62 | returned: success 63 | type: str 64 | sample: default 65 | api_timeout: 66 | description: Timeout used for the API requests 67 | returned: success 68 | type: int 69 | sample: 60 70 | api_retries: 71 | description: Amount of max retries for the API requests 72 | returned: success 73 | type: int 74 | sample: 5 75 | api_retry_max_delay: 76 | description: Exponential backoff delay in seconds between retries up to this max delay value. 77 | returned: success 78 | type: int 79 | sample: 12 80 | api_endpoint: 81 | description: Endpoint used for the API requests 82 | returned: success 83 | type: str 84 | sample: "https://api.vultr.com" 85 | vultr_ssh_key: 86 | description: Response from Vultr API 87 | returned: success 88 | type: complex 89 | contains: 90 | id: 91 | description: ID of the ssh key 92 | returned: success 93 | type: str 94 | sample: 5904bc6ed9234 95 | name: 96 | description: Name of the ssh key 97 | returned: success 98 | type: str 99 | sample: my ssh key 100 | date_created: 101 | description: Date the ssh key was created 102 | returned: success 103 | type: str 104 | sample: "2017-08-26 12:47:48" 105 | ssh_key: 106 | description: SSH public key 107 | returned: success 108 | type: str 109 | sample: "ssh-rsa AA... someother@example.com" 110 | ''' 111 | 112 | from ansible.module_utils.basic import AnsibleModule 113 | from ..module_utils.vultr import ( 114 | Vultr, 115 | vultr_argument_spec, 116 | ) 117 | 118 | 119 | class AnsibleVultrSshKey(Vultr): 120 | 121 | def __init__(self, module): 122 | super(AnsibleVultrSshKey, self).__init__(module, "vultr_ssh_key") 123 | 124 | self.returns = { 125 | 'SSHKEYID': dict(key='id'), 126 | 'name': dict(), 127 | 'ssh_key': dict(), 128 | 'date_created': dict(), 129 | } 130 | 131 | def get_ssh_key(self): 132 | ssh_keys = self.api_query(path="/v1/sshkey/list") 133 | if ssh_keys: 134 | for ssh_key_id, ssh_key_data in ssh_keys.items(): 135 | if ssh_key_data.get('name') == self.module.params.get('name'): 136 | return ssh_key_data 137 | return {} 138 | 139 | def present_ssh_key(self): 140 | ssh_key = self.get_ssh_key() 141 | if not ssh_key: 142 | ssh_key = self._create_ssh_key(ssh_key) 143 | else: 144 | ssh_key = self._update_ssh_key(ssh_key) 145 | return ssh_key 146 | 147 | def _create_ssh_key(self, ssh_key): 148 | self.result['changed'] = True 149 | data = { 150 | 'name': self.module.params.get('name'), 151 | 'ssh_key': self.module.params.get('ssh_key'), 152 | } 153 | self.result['diff']['before'] = {} 154 | self.result['diff']['after'] = data 155 | 156 | if not self.module.check_mode: 157 | self.api_query( 158 | path="/v1/sshkey/create", 159 | method="POST", 160 | data=data 161 | ) 162 | ssh_key = self.get_ssh_key() 163 | return ssh_key 164 | 165 | def _update_ssh_key(self, ssh_key): 166 | param_ssh_key = self.module.params.get('ssh_key') 167 | if param_ssh_key != ssh_key['ssh_key']: 168 | self.result['changed'] = True 169 | 170 | data = { 171 | 'SSHKEYID': ssh_key['SSHKEYID'], 172 | 'ssh_key': param_ssh_key, 173 | } 174 | 175 | self.result['diff']['before'] = ssh_key 176 | self.result['diff']['after'] = data 177 | self.result['diff']['after'].update({'date_created': ssh_key['date_created']}) 178 | 179 | if not self.module.check_mode: 180 | self.api_query( 181 | path="/v1/sshkey/update", 182 | method="POST", 183 | data=data 184 | ) 185 | ssh_key = self.get_ssh_key() 186 | return ssh_key 187 | 188 | def absent_ssh_key(self): 189 | ssh_key = self.get_ssh_key() 190 | if ssh_key: 191 | self.result['changed'] = True 192 | 193 | data = { 194 | 'SSHKEYID': ssh_key['SSHKEYID'], 195 | } 196 | 197 | self.result['diff']['before'] = ssh_key 198 | self.result['diff']['after'] = {} 199 | 200 | if not self.module.check_mode: 201 | self.api_query( 202 | path="/v1/sshkey/destroy", 203 | method="POST", 204 | data=data 205 | ) 206 | return ssh_key 207 | 208 | 209 | def main(): 210 | argument_spec = vultr_argument_spec() 211 | argument_spec.update(dict( 212 | name=dict(type='str', required=True), 213 | ssh_key=dict(type='str', no_log=False), 214 | state=dict(type='str', choices=['present', 'absent'], default='present'), 215 | )) 216 | 217 | module = AnsibleModule( 218 | argument_spec=argument_spec, 219 | required_if=[ 220 | ('state', 'present', ['ssh_key']), 221 | ], 222 | supports_check_mode=True, 223 | ) 224 | 225 | vultr_ssh_key = AnsibleVultrSshKey(module) 226 | if module.params.get('state') == "absent": 227 | ssh_key = vultr_ssh_key.absent_ssh_key() 228 | else: 229 | ssh_key = vultr_ssh_key.present_ssh_key() 230 | 231 | result = vultr_ssh_key.get_result(ssh_key) 232 | module.exit_json(**result) 233 | 234 | 235 | if __name__ == '__main__': 236 | main() 237 | -------------------------------------------------------------------------------- /plugins/modules/vultr_ssh_key_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # Copyright (c) 2019, René Moser 6 | 7 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 8 | 9 | from __future__ import (absolute_import, division, print_function) 10 | __metaclass__ = type 11 | 12 | 13 | DOCUMENTATION = r''' 14 | --- 15 | module: vultr_ssh_key_info 16 | short_description: Get information about the Vultr SSH keys available. 17 | description: 18 | - Get infos about SSH keys available. 19 | version_added: "0.1.0" 20 | author: 21 | - "Yanis Guenane (@Spredzy)" 22 | - "René Moser (@resmo)" 23 | extends_documentation_fragment: 24 | - ngine_io.vultr.vultr 25 | 26 | ''' 27 | 28 | EXAMPLES = r''' 29 | - name: Get Vultr SSH keys infos 30 | ngine_io.vultr.vultr_ssh_key_info: 31 | register: result 32 | 33 | - name: Print the infos 34 | debug: 35 | var: result.vultr_ssh_key_info 36 | ''' 37 | 38 | RETURN = r''' 39 | --- 40 | vultr_api: 41 | description: Response from Vultr API with a few additions/modification 42 | returned: success 43 | type: complex 44 | contains: 45 | api_account: 46 | description: Account used in the ini file to select the key 47 | returned: success 48 | type: str 49 | sample: default 50 | api_timeout: 51 | description: Timeout used for the API requests 52 | returned: success 53 | type: int 54 | sample: 60 55 | api_retries: 56 | description: Amount of max retries for the API requests 57 | returned: success 58 | type: int 59 | sample: 5 60 | api_retry_max_delay: 61 | description: Exponential backoff delay in seconds between retries up to this max delay value. 62 | returned: success 63 | type: int 64 | sample: 12 65 | api_endpoint: 66 | description: Endpoint used for the API requests 67 | returned: success 68 | type: str 69 | sample: "https://api.vultr.com" 70 | vultr_ssh_key_info: 71 | description: Response from Vultr API as list 72 | returned: success 73 | type: complex 74 | contains: 75 | id: 76 | description: ID of the ssh key 77 | returned: success 78 | type: str 79 | sample: 5904bc6ed9234 80 | name: 81 | description: Name of the ssh key 82 | returned: success 83 | type: str 84 | sample: my ssh key 85 | date_created: 86 | description: Date the ssh key was created 87 | returned: success 88 | type: str 89 | sample: "2017-08-26 12:47:48" 90 | ssh_key: 91 | description: SSH public key 92 | returned: success 93 | type: str 94 | sample: "ssh-rsa AA... someother@example.com" 95 | ''' 96 | 97 | from ansible.module_utils.basic import AnsibleModule 98 | from ..module_utils.vultr import ( 99 | Vultr, 100 | vultr_argument_spec, 101 | ) 102 | 103 | 104 | class AnsibleVultrSSHKeyInfo(Vultr): 105 | 106 | def __init__(self, module): 107 | super(AnsibleVultrSSHKeyInfo, self).__init__(module, "vultr_ssh_key_info") 108 | 109 | self.returns = { 110 | 'SSHKEYID': dict(key='id'), 111 | 'name': dict(), 112 | 'ssh_key': dict(), 113 | 'date_created': dict(), 114 | } 115 | 116 | def get_sshkeys(self): 117 | return self.api_query(path="/v1/sshkey/list") 118 | 119 | 120 | def parse_keys_list(keys_list): 121 | if not keys_list: 122 | return [] 123 | 124 | return [key for id, key in keys_list.items()] 125 | 126 | 127 | def main(): 128 | argument_spec = vultr_argument_spec() 129 | 130 | module = AnsibleModule( 131 | argument_spec=argument_spec, 132 | supports_check_mode=True, 133 | ) 134 | 135 | sshkey_info = AnsibleVultrSSHKeyInfo(module) 136 | result = sshkey_info.get_result(parse_keys_list(sshkey_info.get_sshkeys())) 137 | module.exit_json(**result) 138 | 139 | 140 | if __name__ == '__main__': 141 | main() 142 | -------------------------------------------------------------------------------- /plugins/modules/vultr_startup_script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, René Moser 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = r''' 12 | --- 13 | module: vultr_startup_script 14 | short_description: Manages startup scripts on Vultr. 15 | description: 16 | - Create, update and remove startup scripts. 17 | version_added: "0.1.0" 18 | author: "René Moser (@resmo)" 19 | options: 20 | name: 21 | description: 22 | - The script name. 23 | required: true 24 | type: str 25 | script_type: 26 | description: 27 | - The script type, can not be changed once created. 28 | default: boot 29 | choices: [ boot, pxe ] 30 | aliases: [ type ] 31 | type: str 32 | script: 33 | description: 34 | - The script source code. 35 | - Required if I(state=present). 36 | type: str 37 | state: 38 | description: 39 | - State of the script. 40 | default: present 41 | choices: [ present, absent ] 42 | type: str 43 | extends_documentation_fragment: 44 | - ngine_io.vultr.vultr 45 | 46 | ''' 47 | 48 | EXAMPLES = r''' 49 | - name: ensure a pxe script exists, source from a file 50 | ngine_io.vultr.vultr_startup_script: 51 | name: my_web_script 52 | script_type: pxe 53 | script: "{{ lookup('file', 'path/to/script') }}" 54 | 55 | - name: ensure a boot script exists 56 | ngine_io.vultr.vultr_startup_script: 57 | name: vultr_startup_script 58 | script: "#!/bin/bash\necho Hello World > /root/hello" 59 | 60 | - name: ensure a script is absent 61 | ngine_io.vultr.vultr_startup_script: 62 | name: my_web_script 63 | state: absent 64 | ''' 65 | 66 | RETURN = r''' 67 | --- 68 | vultr_api: 69 | description: Response from Vultr API with a few additions/modification 70 | returned: success 71 | type: complex 72 | contains: 73 | api_account: 74 | description: Account used in the ini file to select the key 75 | returned: success 76 | type: str 77 | sample: default 78 | api_timeout: 79 | description: Timeout used for the API requests 80 | returned: success 81 | type: int 82 | sample: 60 83 | api_retries: 84 | description: Amount of max retries for the API requests 85 | returned: success 86 | type: int 87 | sample: 5 88 | api_retry_max_delay: 89 | description: Exponential backoff delay in seconds between retries up to this max delay value. 90 | returned: success 91 | type: int 92 | sample: 12 93 | api_endpoint: 94 | description: Endpoint used for the API requests 95 | returned: success 96 | type: str 97 | sample: "https://api.vultr.com" 98 | vultr_startup_script: 99 | description: Response from Vultr API 100 | returned: success 101 | type: complex 102 | contains: 103 | id: 104 | description: ID of the startup script. 105 | returned: success 106 | type: str 107 | sample: 249395 108 | name: 109 | description: Name of the startup script. 110 | returned: success 111 | type: str 112 | sample: my startup script 113 | script: 114 | description: The source code of the startup script. 115 | returned: success 116 | type: str 117 | sample: "#!/bin/bash\necho Hello World > /root/hello" 118 | script_type: 119 | description: The type of the startup script. 120 | returned: success 121 | type: str 122 | sample: pxe 123 | date_created: 124 | description: Date the startup script was created. 125 | returned: success 126 | type: str 127 | sample: "2017-08-26 12:47:48" 128 | date_modified: 129 | description: Date the startup script was modified. 130 | returned: success 131 | type: str 132 | sample: "2017-08-26 12:47:48" 133 | ''' 134 | 135 | from ansible.module_utils.basic import AnsibleModule 136 | from ..module_utils.vultr import ( 137 | Vultr, 138 | vultr_argument_spec, 139 | ) 140 | 141 | 142 | class AnsibleVultrStartupScript(Vultr): 143 | 144 | def __init__(self, module): 145 | super(AnsibleVultrStartupScript, self).__init__(module, "vultr_startup_script") 146 | 147 | self.returns = { 148 | 'SCRIPTID': dict(key='id'), 149 | 'type': dict(key='script_type'), 150 | 'name': dict(), 151 | 'script': dict(), 152 | 'date_created': dict(), 153 | 'date_modified': dict(), 154 | } 155 | 156 | def get_script(self): 157 | scripts = self.api_query(path="/v1/startupscript/list") 158 | name = self.module.params.get('name') 159 | if scripts: 160 | for script_id, script_data in scripts.items(): 161 | if script_data.get('name') == name: 162 | return script_data 163 | return {} 164 | 165 | def present_script(self): 166 | script = self.get_script() 167 | if not script: 168 | script = self._create_script(script) 169 | else: 170 | script = self._update_script(script) 171 | return script 172 | 173 | def _create_script(self, script): 174 | self.result['changed'] = True 175 | 176 | data = { 177 | 'name': self.module.params.get('name'), 178 | 'script': self.module.params.get('script'), 179 | 'type': self.module.params.get('script_type'), 180 | } 181 | 182 | self.result['diff']['before'] = {} 183 | self.result['diff']['after'] = data 184 | 185 | if not self.module.check_mode: 186 | self.api_query( 187 | path="/v1/startupscript/create", 188 | method="POST", 189 | data=data 190 | ) 191 | script = self.get_script() 192 | return script 193 | 194 | def _update_script(self, script): 195 | if script['script'] != self.module.params.get('script'): 196 | self.result['changed'] = True 197 | 198 | data = { 199 | 'SCRIPTID': script['SCRIPTID'], 200 | 'script': self.module.params.get('script'), 201 | } 202 | 203 | self.result['diff']['before'] = script 204 | self.result['diff']['after'] = script.copy() 205 | self.result['diff']['after'].update(data) 206 | 207 | if not self.module.check_mode: 208 | self.api_query( 209 | path="/v1/startupscript/update", 210 | method="POST", 211 | data=data 212 | ) 213 | script = self.get_script() 214 | return script 215 | 216 | def absent_script(self): 217 | script = self.get_script() 218 | if script: 219 | self.result['changed'] = True 220 | 221 | data = { 222 | 'SCRIPTID': script['SCRIPTID'], 223 | } 224 | 225 | self.result['diff']['before'] = script 226 | self.result['diff']['after'] = {} 227 | 228 | if not self.module.check_mode: 229 | self.api_query( 230 | path="/v1/startupscript/destroy", 231 | method="POST", 232 | data=data 233 | ) 234 | return script 235 | 236 | 237 | def main(): 238 | argument_spec = vultr_argument_spec() 239 | argument_spec.update(dict( 240 | name=dict(type='str', required=True), 241 | script=dict(type='str',), 242 | script_type=dict(type='str', default='boot', choices=['boot', 'pxe'], aliases=['type']), 243 | state=dict(type='str', choices=['present', 'absent'], default='present'), 244 | )) 245 | 246 | module = AnsibleModule( 247 | argument_spec=argument_spec, 248 | required_if=[ 249 | ('state', 'present', ['script']), 250 | ], 251 | supports_check_mode=True, 252 | ) 253 | 254 | vultr_script = AnsibleVultrStartupScript(module) 255 | if module.params.get('state') == "absent": 256 | script = vultr_script.absent_script() 257 | else: 258 | script = vultr_script.present_script() 259 | 260 | result = vultr_script.get_result(script) 261 | module.exit_json(**result) 262 | 263 | 264 | if __name__ == '__main__': 265 | main() 266 | -------------------------------------------------------------------------------- /plugins/modules/vultr_startup_script_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = r''' 12 | --- 13 | module: vultr_startup_script_info 14 | short_description: Gather information about the Vultr startup scripts available. 15 | description: 16 | - Gather information about vultr_startup_scripts available. 17 | version_added: "0.1.0" 18 | author: "Yanis Guenane (@Spredzy)" 19 | extends_documentation_fragment: 20 | - ngine_io.vultr.vultr 21 | 22 | ''' 23 | 24 | EXAMPLES = r''' 25 | - name: Gather Vultr startup scripts information 26 | ngine_io.vultr.vultr_startup_script_info: 27 | register: result 28 | 29 | - name: Print the gathered information 30 | debug: 31 | var: result.vultr_startup_script_info 32 | ''' 33 | 34 | RETURN = r''' 35 | --- 36 | vultr_api: 37 | description: Response from Vultr API with a few additions/modification 38 | returned: success 39 | type: complex 40 | contains: 41 | api_account: 42 | description: Account used in the ini file to select the key 43 | returned: success 44 | type: str 45 | sample: default 46 | api_timeout: 47 | description: Timeout used for the API requests 48 | returned: success 49 | type: int 50 | sample: 60 51 | api_retries: 52 | description: Amount of max retries for the API requests 53 | returned: success 54 | type: int 55 | sample: 5 56 | api_retry_max_delay: 57 | description: Exponential backoff delay in seconds between retries up to this max delay value. 58 | returned: success 59 | type: int 60 | sample: 12 61 | api_endpoint: 62 | description: Endpoint used for the API requests 63 | returned: success 64 | type: str 65 | sample: "https://api.vultr.com" 66 | vultr_startup_script_info: 67 | description: Response from Vultr API 68 | returned: success 69 | type: complex 70 | contains: 71 | id: 72 | description: ID of the startup script. 73 | returned: success 74 | type: str 75 | sample: 249395 76 | name: 77 | description: Name of the startup script. 78 | returned: success 79 | type: str 80 | sample: my startup script 81 | script: 82 | description: The source code of the startup script. 83 | returned: success 84 | type: str 85 | sample: "#!/bin/bash\necho Hello World > /root/hello" 86 | type: 87 | description: The type of the startup script. 88 | returned: success 89 | type: str 90 | sample: pxe 91 | date_created: 92 | description: Date the startup script was created. 93 | returned: success 94 | type: str 95 | sample: "2017-08-26 12:47:48" 96 | date_modified: 97 | description: Date the startup script was modified. 98 | returned: success 99 | type: str 100 | sample: "2017-08-26 12:47:48" 101 | ''' 102 | 103 | from ansible.module_utils.basic import AnsibleModule 104 | from ..module_utils.vultr import ( 105 | Vultr, 106 | vultr_argument_spec, 107 | ) 108 | 109 | 110 | class AnsibleVultrStartupScriptInfo(Vultr): 111 | 112 | def __init__(self, module): 113 | super(AnsibleVultrStartupScriptInfo, self).__init__(module, "vultr_startup_script_info") 114 | 115 | self.returns = { 116 | "SCRIPTID": dict(key='id', convert_to='int'), 117 | "date_created": dict(), 118 | "date_modified": dict(), 119 | "name": dict(), 120 | "script": dict(), 121 | "type": dict(), 122 | } 123 | 124 | def get_startupscripts(self): 125 | return self.api_query(path="/v1/startupscript/list") 126 | 127 | 128 | def parse_startupscript_list(startupscipts_list): 129 | if not startupscipts_list: 130 | return [] 131 | 132 | return [startupscript for id, startupscript in startupscipts_list.items()] 133 | 134 | 135 | def main(): 136 | argument_spec = vultr_argument_spec() 137 | 138 | module = AnsibleModule( 139 | argument_spec=argument_spec, 140 | supports_check_mode=True, 141 | ) 142 | 143 | startupscript_info = AnsibleVultrStartupScriptInfo(module) 144 | result = startupscript_info.get_result(parse_startupscript_list(startupscript_info.get_startupscripts())) 145 | module.exit_json(**result) 146 | 147 | 148 | if __name__ == '__main__': 149 | main() 150 | -------------------------------------------------------------------------------- /plugins/modules/vultr_user.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2017, René Moser 5 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 6 | 7 | from __future__ import (absolute_import, division, print_function) 8 | __metaclass__ = type 9 | 10 | 11 | DOCUMENTATION = r''' 12 | --- 13 | module: vultr_user 14 | short_description: Manages users on Vultr. 15 | description: 16 | - Create, update and remove users. 17 | version_added: "0.1.0" 18 | author: "René Moser (@resmo)" 19 | options: 20 | name: 21 | description: 22 | - Name of the user 23 | required: true 24 | type: str 25 | email: 26 | description: 27 | - Email of the user. 28 | - Required if C(state=present). 29 | type: str 30 | password: 31 | description: 32 | - Password of the user. 33 | - Only considered while creating a user or when C(force=yes). 34 | type: str 35 | force: 36 | description: 37 | - Password will only be changed with enforcement. 38 | default: no 39 | type: bool 40 | api_enabled: 41 | description: 42 | - Whether the API is enabled or not. 43 | default: yes 44 | type: bool 45 | acls: 46 | description: 47 | - List of ACLs this users should have, see U(https://www.vultr.com/api/#user_user_list). 48 | - Required if C(state=present). 49 | - One or more of the choices list, some depend on each other. 50 | choices: 51 | - manage_users 52 | - subscriptions 53 | - provisioning 54 | - billing 55 | - support 56 | - abuse 57 | - dns 58 | - upgrade 59 | aliases: [ acl ] 60 | type: list 61 | elements: str 62 | state: 63 | description: 64 | - State of the user. 65 | default: present 66 | choices: [ present, absent ] 67 | type: str 68 | extends_documentation_fragment: 69 | - ngine_io.vultr.vultr 70 | 71 | ''' 72 | 73 | EXAMPLES = r''' 74 | - name: Ensure a user exists 75 | ngine_io.vultr.vultr_user: 76 | name: john 77 | email: john.doe@example.com 78 | password: s3cr3t 79 | acls: 80 | - upgrade 81 | - dns 82 | - manage_users 83 | - subscriptions 84 | - upgrade 85 | 86 | - name: Remove a user 87 | ngine_io.vultr.vultr_user: 88 | name: john 89 | state: absent 90 | ''' 91 | 92 | RETURN = r''' 93 | --- 94 | vultr_api: 95 | description: Response from Vultr API with a few additions/modification 96 | returned: success 97 | type: complex 98 | contains: 99 | api_account: 100 | description: Account used in the ini file to select the key 101 | returned: success 102 | type: str 103 | sample: default 104 | api_timeout: 105 | description: Timeout used for the API requests 106 | returned: success 107 | type: int 108 | sample: 60 109 | api_retries: 110 | description: Amount of max retries for the API requests 111 | returned: success 112 | type: int 113 | sample: 5 114 | api_retry_max_delay: 115 | description: Exponential backoff delay in seconds between retries up to this max delay value. 116 | returned: success 117 | type: int 118 | sample: 12 119 | api_endpoint: 120 | description: Endpoint used for the API requests 121 | returned: success 122 | type: str 123 | sample: "https://api.vultr.com" 124 | vultr_user: 125 | description: Response from Vultr API 126 | returned: success 127 | type: complex 128 | contains: 129 | id: 130 | description: ID of the user. 131 | returned: success 132 | type: str 133 | sample: 5904bc6ed9234 134 | api_key: 135 | description: API key of the user. 136 | returned: only after resource was created 137 | type: str 138 | sample: 567E6K567E6K567E6K567E6K567E6K 139 | name: 140 | description: Name of the user. 141 | returned: success 142 | type: str 143 | sample: john 144 | email: 145 | description: Email of the user. 146 | returned: success 147 | type: str 148 | sample: "john@example.com" 149 | api_enabled: 150 | description: Whether the API is enabled or not. 151 | returned: success 152 | type: bool 153 | sample: true 154 | acls: 155 | description: List of ACLs of the user. 156 | returned: success 157 | type: list 158 | sample: [manage_users, support, upgrade] 159 | ''' 160 | 161 | from ansible.module_utils.basic import AnsibleModule 162 | from ..module_utils.vultr import ( 163 | Vultr, 164 | vultr_argument_spec, 165 | ) 166 | 167 | 168 | ACLS = [ 169 | 'manage_users', 170 | 'subscriptions', 171 | 'provisioning', 172 | 'billing', 173 | 'support', 174 | 'abuse', 175 | 'dns', 176 | 'upgrade', 177 | ] 178 | 179 | 180 | class AnsibleVultrUser(Vultr): 181 | 182 | def __init__(self, module): 183 | super(AnsibleVultrUser, self).__init__(module, "vultr_user") 184 | 185 | self.returns = { 186 | 'USERID': dict(key='id'), 187 | 'name': dict(), 188 | 'email': dict(), 189 | 'api_enabled': dict(convert_to='bool'), 190 | 'acls': dict(), 191 | 'api_key': dict() 192 | } 193 | 194 | def _common_args(self): 195 | return { 196 | 'name': self.module.params.get('name'), 197 | 'email': self.module.params.get('email'), 198 | 'acls': self.module.params.get('acls'), 199 | 'password': self.module.params.get('password'), 200 | 'api_enabled': self.get_yes_or_no('api_enabled'), 201 | } 202 | 203 | def get_user(self): 204 | users = self.api_query(path="/v1/user/list") 205 | for user in users or []: 206 | if user.get('name') == self.module.params.get('name'): 207 | return user 208 | return {} 209 | 210 | def present_user(self): 211 | user = self.get_user() 212 | if not user: 213 | user = self._create_user(user) 214 | else: 215 | user = self._update_user(user) 216 | return user 217 | 218 | def _has_changed(self, user, data): 219 | for k, v in data.items(): 220 | if k not in user: 221 | continue 222 | elif isinstance(v, list): 223 | for i in v: 224 | if i not in user[k]: 225 | return True 226 | elif data[k] != user[k]: 227 | return True 228 | return False 229 | 230 | def _create_user(self, user): 231 | self.module.fail_on_missing_params(required_params=['password']) 232 | 233 | self.result['changed'] = True 234 | 235 | data = self._common_args() 236 | self.result['diff']['before'] = {} 237 | self.result['diff']['after'] = data 238 | 239 | if not self.module.check_mode: 240 | user = self.api_query( 241 | path="/v1/user/create", 242 | method="POST", 243 | data=data 244 | ) 245 | user.update(self.get_user()) 246 | return user 247 | 248 | def _update_user(self, user): 249 | data = self._common_args() 250 | data.update({ 251 | 'USERID': user['USERID'], 252 | }) 253 | 254 | force = self.module.params.get('force') 255 | if not force: 256 | del data['password'] 257 | 258 | if force or self._has_changed(user=user, data=data): 259 | self.result['changed'] = True 260 | 261 | self.result['diff']['before'] = user 262 | self.result['diff']['after'] = user.copy() 263 | self.result['diff']['after'].update(data) 264 | 265 | if not self.module.check_mode: 266 | self.api_query( 267 | path="/v1/user/update", 268 | method="POST", 269 | data=data 270 | ) 271 | user = self.get_user() 272 | return user 273 | 274 | def absent_user(self): 275 | user = self.get_user() 276 | if user: 277 | self.result['changed'] = True 278 | 279 | data = { 280 | 'USERID': user['USERID'], 281 | } 282 | 283 | self.result['diff']['before'] = user 284 | self.result['diff']['after'] = {} 285 | 286 | if not self.module.check_mode: 287 | self.api_query( 288 | path="/v1/user/delete", 289 | method="POST", 290 | data=data 291 | ) 292 | return user 293 | 294 | 295 | def main(): 296 | argument_spec = vultr_argument_spec() 297 | argument_spec.update(dict( 298 | name=dict(type='str', required=True), 299 | email=dict(type='str',), 300 | password=dict(type='str', no_log=True), 301 | force=dict(type='bool', default=False), 302 | api_enabled=dict(type='bool', default=True), 303 | acls=dict(type='list', elements='str', choices=ACLS, aliases=['acl']), 304 | state=dict(type='str', choices=['present', 'absent'], default='present'), 305 | )) 306 | 307 | module = AnsibleModule( 308 | argument_spec=argument_spec, 309 | required_if=[ 310 | ('state', 'present', ['email', 'acls']), 311 | ], 312 | supports_check_mode=True, 313 | ) 314 | 315 | vultr_user = AnsibleVultrUser(module) 316 | if module.params.get('state') == "absent": 317 | user = vultr_user.absent_user() 318 | else: 319 | user = vultr_user.present_user() 320 | 321 | result = vultr_user.get_result(user) 322 | module.exit_json(**result) 323 | 324 | 325 | if __name__ == '__main__': 326 | main() 327 | -------------------------------------------------------------------------------- /plugins/modules/vultr_user_info.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # Copyright (c) 2018, Yanis Guenane 5 | # Copyright (c) 2019, René Moser 6 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 7 | 8 | from __future__ import (absolute_import, division, print_function) 9 | __metaclass__ = type 10 | 11 | 12 | DOCUMENTATION = r''' 13 | --- 14 | module: vultr_user_info 15 | short_description: Get information about the Vultr user available. 16 | version_added: "0.1.0" 17 | description: 18 | - Get infos about users available in Vultr. 19 | author: 20 | - "Yanis Guenane (@Spredzy)" 21 | - "René Moser (@resmo)" 22 | extends_documentation_fragment: 23 | - ngine_io.vultr.vultr 24 | 25 | ''' 26 | 27 | EXAMPLES = r''' 28 | - name: Get Vultr user infos 29 | ngine_io.vultr.vultr_user_info: 30 | register: result 31 | 32 | - name: Print the infos 33 | debug: 34 | var: result.vultr_user_info 35 | ''' 36 | 37 | RETURN = r''' 38 | --- 39 | vultr_api: 40 | description: Response from Vultr API with a few additions/modification 41 | returned: success 42 | type: complex 43 | contains: 44 | api_account: 45 | description: Account used in the ini file to select the key 46 | returned: success 47 | type: str 48 | sample: default 49 | api_timeout: 50 | description: Timeout used for the API requests 51 | returned: success 52 | type: int 53 | sample: 60 54 | api_retries: 55 | description: Amount of max retries for the API requests 56 | returned: success 57 | type: int 58 | sample: 5 59 | api_retry_max_delay: 60 | description: Exponential backoff delay in seconds between retries up to this max delay value. 61 | returned: success 62 | type: int 63 | sample: 12 64 | api_endpoint: 65 | description: Endpoint used for the API requests 66 | returned: success 67 | type: str 68 | sample: "https://api.vultr.com" 69 | vultr_user_info: 70 | description: Response from Vultr API as list 71 | returned: available 72 | type: complex 73 | contains: 74 | id: 75 | description: ID of the user. 76 | returned: success 77 | type: str 78 | sample: 5904bc6ed9234 79 | api_key: 80 | description: API key of the user. 81 | returned: only after resource was created 82 | type: str 83 | sample: 567E6K567E6K567E6K567E6K567E6K 84 | name: 85 | description: Name of the user. 86 | returned: success 87 | type: str 88 | sample: john 89 | email: 90 | description: Email of the user. 91 | returned: success 92 | type: str 93 | sample: "john@example.com" 94 | api_enabled: 95 | description: Whether the API is enabled or not. 96 | returned: success 97 | type: bool 98 | sample: true 99 | acls: 100 | description: List of ACLs of the user. 101 | returned: success 102 | type: list 103 | sample: [ manage_users, support, upgrade ] 104 | ''' 105 | 106 | from ansible.module_utils.basic import AnsibleModule 107 | from ..module_utils.vultr import ( 108 | Vultr, 109 | vultr_argument_spec, 110 | ) 111 | 112 | 113 | class AnsibleVultrUserInfo(Vultr): 114 | 115 | def __init__(self, module): 116 | super(AnsibleVultrUserInfo, self).__init__(module, "vultr_user_info") 117 | 118 | self.returns = { 119 | "USERID": dict(key='id'), 120 | "acls": dict(), 121 | "api_enabled": dict(), 122 | "email": dict(), 123 | "name": dict() 124 | } 125 | 126 | def get_regions(self): 127 | return self.api_query(path="/v1/user/list") 128 | 129 | 130 | def main(): 131 | argument_spec = vultr_argument_spec() 132 | 133 | module = AnsibleModule( 134 | argument_spec=argument_spec, 135 | supports_check_mode=True, 136 | ) 137 | 138 | user_info = AnsibleVultrUserInfo(module) 139 | result = user_info.get_result(user_info.get_regions()) 140 | module.exit_json(**result) 141 | 142 | 143 | if __name__ == '__main__': 144 | main() 145 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_account_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | smoke/vultr 3 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_account_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test get vultr account infos in check mode 5 | vultr_account_info: 6 | check_mode: yes 7 | register: result 8 | 9 | - name: verify test get vultr account infos in check mode 10 | assert: 11 | that: 12 | - result.vultr_account_info.balance is defined 13 | - result.vultr_account_info.last_payment_amount is defined 14 | - result.vultr_account_info.last_payment_date is defined 15 | - result.vultr_account_info.last_payment_amount is defined 16 | 17 | - name: test get vultr account fact 18 | vultr_account_info: 19 | register: result 20 | 21 | - name: verify test get vultr account infos 22 | assert: 23 | that: 24 | - result.vultr_account_info.balance is defined 25 | - result.vultr_account_info.last_payment_amount is defined 26 | - result.vultr_account_info.last_payment_date is defined 27 | - result.vultr_account_info.last_payment_amount is defined 28 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_block_storage/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_block_storage/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr-test-prefix" 3 | vultr_block_storage_name: "{{ vultr_resource_prefix }}-volume" 4 | vultr_block_storage_size: 10 5 | vultr_block_storage_size_2: 12 6 | vultr_block_storage_size_3: 14 7 | vultr_block_storage_region: New Jersey 8 | 9 | vultr_server_name: "{{ vultr_resource_prefix }}_vm_for_attachment" 10 | vultr_server_ssh_keys: 11 | - name: key1 12 | key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= mail@renemoser.net" 13 | 14 | vultr_server_plan_1: 1024 MB RAM,25 GB SSD,1.00 TB BW 15 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_block_storage/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup 5 | vultr_block_storage: 6 | name: "{{ vultr_block_storage_name }}" 7 | state: absent 8 | register: result 9 | - name: verify setup 10 | assert: 11 | that: 12 | - result is success 13 | 14 | - name: setup create ssh keys 15 | vultr_ssh_key: 16 | name: "{{ item.name }}" 17 | ssh_key: "{{ item.key }}" 18 | loop: "{{ vultr_server_ssh_keys }}" 19 | 20 | - name: Setup create server for attachment 21 | # We'll use this server to test block storage attachment, later 22 | # in this test suite. 23 | vultr_server: 24 | name: "{{ vultr_server_name }}" 25 | os: CentOS 8 x64 26 | plan: "{{ vultr_server_plan_1 }}" 27 | ssh_keys: 28 | - key1 29 | region: "{{ vultr_block_storage_region }}" 30 | state: started 31 | register: result_server_setup 32 | - name: verify setup create server 33 | assert: 34 | that: 35 | - result_server_setup is changed 36 | 37 | - name: test fail if missing name 38 | vultr_block_storage: 39 | register: result 40 | ignore_errors: yes 41 | - name: verify test fail if missing name 42 | assert: 43 | that: 44 | - result is failed 45 | - 'result.msg == "missing required arguments: name"' 46 | 47 | - name: test fail if missing params for state=present 48 | vultr_block_storage: 49 | name: "{{ vultr_block_storage_name }}" 50 | register: result 51 | ignore_errors: yes 52 | - name: verify fail if missing params for state=present 53 | assert: 54 | that: 55 | - result is failed 56 | - 'result.msg == "state is present but all of the following are missing: size, region"' 57 | 58 | - name: test create block storage volume in check mode 59 | vultr_block_storage: 60 | name: "{{ vultr_block_storage_name }}" 61 | size: "{{ vultr_block_storage_size }}" 62 | region: "{{ vultr_block_storage_region }}" 63 | register: result 64 | check_mode: yes 65 | - name: verify test create server in check mode 66 | assert: 67 | that: 68 | - result is changed 69 | 70 | - name: test create block storage volume 71 | vultr_block_storage: 72 | name: "{{ vultr_block_storage_name }}" 73 | size: "{{ vultr_block_storage_size }}" 74 | region: "{{ vultr_block_storage_region }}" 75 | register: result 76 | - name: verify test create block storage volume 77 | assert: 78 | that: 79 | - result is changed 80 | - result.vultr_block_storage.name == "{{ vultr_block_storage_name }}" 81 | - result.vultr_block_storage.region == "{{ vultr_block_storage_region }}" 82 | - result.vultr_block_storage.size == 10 83 | 84 | - name: test create block storage volume idempotence 85 | vultr_block_storage: 86 | name: "{{ vultr_block_storage_name }}" 87 | size: "{{ vultr_block_storage_size }}" 88 | region: "{{ vultr_block_storage_region }}" 89 | register: result 90 | - name: verify test block storage volume idempotence 91 | assert: 92 | that: 93 | - result is not changed 94 | - result.vultr_block_storage.name == "{{ vultr_block_storage_name }}" 95 | - result.vultr_block_storage.region == "{{ vultr_block_storage_region }}" 96 | - result.vultr_block_storage.size == 10 97 | 98 | # volumes size can only be modified every 60s 99 | - name: wait about 60s before resizing volume 100 | wait_for: 101 | timeout: 65 102 | 103 | - name: test resize block storage volume 104 | vultr_block_storage: 105 | name: "{{ vultr_block_storage_name }}" 106 | size: "{{ vultr_block_storage_size_2 }}" 107 | region: "{{ vultr_block_storage_region }}" 108 | register: result 109 | - name: verify resize block storage volume 110 | assert: 111 | that: 112 | - result is changed 113 | - 'result.vultr_block_storage.size == {{ vultr_block_storage_size_2 | int }}' 114 | 115 | # volume size can only be modified every 60s 116 | - name: wait about 60s before resizing volume 117 | wait_for: 118 | timeout: 65 119 | 120 | - name: test resize block storage volume idempotency 121 | vultr_block_storage: 122 | name: "{{ vultr_block_storage_name }}" 123 | size: "{{ vultr_block_storage_size_2 }}" 124 | region: "{{ vultr_block_storage_region }}" 125 | register: result 126 | - name: verify resize block storage volume idempotency 127 | assert: 128 | that: 129 | - not result.changed 130 | - 'result.vultr_block_storage.size == {{ vultr_block_storage_size_2 | int }}' 131 | 132 | - name: test attaching fails if server id not provided 133 | vultr_block_storage: 134 | name: "{{ vultr_block_storage_name }}" 135 | size: "{{ vultr_block_storage_size }}" 136 | region: "{{ vultr_block_storage_region }}" 137 | state: attached 138 | register: result 139 | ignore_errors: yes 140 | - name: verify attaching fails if server id not provided 141 | assert: 142 | that: 143 | - result is failed 144 | - 'result.msg == "state is attached but all of the following are missing: attached_to_SUBID"' 145 | 146 | - name: test attach block volume in check mode 147 | vultr_block_storage: 148 | name: "{{ vultr_block_storage_name }}" 149 | size: "{{ vultr_block_storage_size }}" 150 | region: "{{ vultr_block_storage_region }}" 151 | state: attached 152 | attached_to_id: 1337 # dummy server id 153 | register: result 154 | check_mode: yes 155 | - name: verify attach block volume in check mode 156 | assert: 157 | that: 158 | - result is changed 159 | - result.vultr_block_storage.attached_to_id == 1337 160 | 161 | - name: test attach block volume 162 | vultr_block_storage: 163 | name: "{{ vultr_block_storage_name }}" 164 | size: "{{ vultr_block_storage_size }}" 165 | region: "{{ vultr_block_storage_region }}" 166 | state: attached 167 | attached_to_SUBID: "{{ result_server_setup.vultr_server.id | int}}" 168 | register: result 169 | - name: verify attach block volume 170 | assert: 171 | that: 172 | - result.changed 173 | - 'result.vultr_block_storage.attached_to_id == {{ result_server_setup.vultr_server.id | int }}' 174 | 175 | - name: test attach block volume idempotency 176 | vultr_block_storage: 177 | name: "{{ vultr_block_storage_name }}" 178 | size: "{{ vultr_block_storage_size }}" 179 | region: "{{ vultr_block_storage_region }}" 180 | state: attached 181 | attached_to_SUBID: "{{ result_server_setup.vultr_server.id | int }}" 182 | register: result 183 | - name: verify attach block volume idempotency 184 | assert: 185 | that: 186 | - not result.changed 187 | - 'result.vultr_block_storage.attached_to_id == {{ result_server_setup.vultr_server.id | int }}' 188 | 189 | # volume size can only be modified every 60s 190 | - name: wait about 60s before resizing volume 191 | wait_for: 192 | timeout: 65 193 | 194 | - name: test resize block storage volume while attaching 195 | vultr_block_storage: 196 | name: "{{ vultr_block_storage_name }}" 197 | size: "{{ vultr_block_storage_size_3 }}" 198 | region: "{{ vultr_block_storage_region }}" 199 | state: attached 200 | attached_to_SUBID: "{{ result_server_setup.vultr_server.id | int }}" 201 | register: result 202 | - name: verify resize block storage volume 203 | assert: 204 | that: 205 | - result is changed 206 | - 'result.vultr_block_storage.size == {{ vultr_block_storage_size_3 | int }}' 207 | 208 | - name: test attach block volume fails if attached somewhere else 209 | vultr_block_storage: 210 | name: "{{ vultr_block_storage_name }}" 211 | size: "{{ vultr_block_storage_size }}" 212 | region: "{{ vultr_block_storage_region }}" 213 | state: attached 214 | attached_to_SUBID: 1337 # some other server 215 | register: result 216 | ignore_errors: true 217 | - name: verify attach block volume fails if attached somewhere else 218 | assert: 219 | that: 220 | - result is failed 221 | - 'result.msg == "Volume already attached to server {{ result_server_setup.vultr_server.id | int }}"' 222 | 223 | - name: test detach block volume in check mode 224 | vultr_block_storage: 225 | name: "{{ vultr_block_storage_name }}" 226 | size: "{{ vultr_block_storage_size }}" 227 | region: "{{ vultr_block_storage_region }}" 228 | state: detached 229 | register: result 230 | check_mode: yes 231 | - name: verify detach block volume 232 | assert: 233 | that: 234 | - result is changed 235 | - not result.vultr_block_storage.attached_to_id 236 | 237 | - name: test detach block volume 238 | vultr_block_storage: 239 | name: "{{ vultr_block_storage_name }}" 240 | size: "{{ vultr_block_storage_size }}" 241 | region: "{{ vultr_block_storage_region }}" 242 | state: detached 243 | register: result 244 | - name: verify detach block volume 245 | assert: 246 | that: 247 | - result is changed 248 | - not result.vultr_block_storage.attached_to_id 249 | 250 | - name: test detach block volume idempotency 251 | vultr_block_storage: 252 | name: "{{ vultr_block_storage_name }}" 253 | size: "{{ vultr_block_storage_size }}" 254 | region: "{{ vultr_block_storage_region }}" 255 | state: detached 256 | register: result 257 | - name: verify detach block volume idempotency 258 | assert: 259 | that: 260 | - result is not changed 261 | - not result.vultr_block_storage.attached_to_id 262 | 263 | - name: test destroy block storage volume in check mode 264 | vultr_block_storage: 265 | name: "{{ vultr_block_storage_name }}" 266 | state: absent 267 | register: result 268 | check_mode: yes 269 | - name: verify test destroy block storage volume in check mode 270 | assert: 271 | that: 272 | - result is changed 273 | - result.vultr_block_storage.name == "{{ vultr_block_storage_name }}" 274 | 275 | - name: test destroy block storage volume 276 | vultr_block_storage: 277 | name: "{{ vultr_block_storage_name }}" 278 | state: absent 279 | register: result 280 | - name: verify test destroy an existing block storage volume 281 | assert: 282 | that: 283 | - result is changed 284 | - result.vultr_block_storage.name == "{{ vultr_block_storage_name }}" 285 | 286 | - name: test destroy an existing block storage volume idempotence 287 | vultr_block_storage: 288 | name: "{{ vultr_block_storage_name }}" 289 | state: absent 290 | register: result 291 | - name: verify test destroy an existing block storage volume idempotence 292 | assert: 293 | that: 294 | - result is not changed 295 | 296 | # Servers can only be destroyed 5 min after creation 297 | - name: wait for 5 min before destroying server 298 | wait_for: 299 | 300 | - name: cleanup server 301 | vultr_server: 302 | name: "{{ vultr_server_name }}" 303 | state: absent 304 | register: result 305 | - name: verify test absent server 306 | assert: 307 | that: 308 | - result is changed 309 | 310 | - name: cleanup ssh keys 311 | vultr_ssh_key: 312 | name: "{{ item.name }}" 313 | ssh_key: "{{ item.key }}" 314 | state: absent 315 | loop: "{{ vultr_server_ssh_keys }}" 316 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_block_storage_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_block_storage_info/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr-test-prefix" 3 | vultr_block_storage_name: "{{ vultr_resource_prefix }}-volume" 4 | vultr_block_storage_size: 10 5 | vultr_block_storage_region: New Jersey 6 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_block_storage_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test gather vultr block storage volume info - empty resource 5 | vultr_block_storage_info: 6 | 7 | - name: Create the block storage volume 8 | vultr_block_storage: 9 | name: '{{ vultr_block_storage_name }}' 10 | size: '{{ vultr_block_storage_size }}' 11 | region: '{{ vultr_block_storage_region }}' 12 | 13 | - name: test gather vultr block storage volume info in check mode 14 | vultr_block_storage_info: 15 | check_mode: yes 16 | register: result 17 | 18 | - name: verify test gather vultr block storage volume info in check mode 19 | assert: 20 | that: 21 | - result.vultr_block_storage_info|selectattr('name','equalto','{{ vultr_block_storage_name }}') | list | count == 1 22 | 23 | - name: test gather vultr block storage volume info 24 | vultr_block_storage_info: 25 | register: result 26 | 27 | - name: verify test gather vultr block storage volume info 28 | assert: 29 | that: 30 | - result.vultr_block_storage_info|selectattr('name','equalto','{{ vultr_block_storage_name }}') | list | count == 1 31 | 32 | - name: Delete the block storage volume 33 | vultr_block_storage: 34 | name: '{{ vultr_block_storage_name }}' 35 | state: absent 36 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_domain/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_domain/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | vultr_resource_prefix: "vultr-test-prefix" 5 | vultr_dns_domain_name: "{{ vultr_resource_prefix }}-example-ansible.com" 6 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_domain/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup 5 | vultr_dns_domain: 6 | name: "{{ vultr_dns_domain_name }}" 7 | state: absent 8 | register: result 9 | - name: verify setup 10 | assert: 11 | that: 12 | - result is success 13 | 14 | - name: test fail if missing name 15 | vultr_dns_domain: 16 | register: result 17 | ignore_errors: yes 18 | - name: verify test fail if missing name 19 | assert: 20 | that: 21 | - result is failed 22 | - 'result.msg == "missing required arguments: name"' 23 | 24 | - name: test fail if missing params for state=present 25 | vultr_dns_domain: 26 | name: "{{ vultr_dns_domain_name }}" 27 | register: result 28 | ignore_errors: yes 29 | - name: verify fail if missing params for state=present 30 | assert: 31 | that: 32 | - result is failed 33 | - 'result.msg == "state is present but all of the following are missing: server_ip"' 34 | 35 | - name: test create dns domain in check mode 36 | vultr_dns_domain: 37 | name: "{{ vultr_dns_domain_name }}" 38 | server_ip: 10.10.10.10 39 | register: result 40 | check_mode: yes 41 | - name: verify test create dns domain in check mode 42 | assert: 43 | that: 44 | - result is changed 45 | 46 | - name: test create dns domain 47 | vultr_dns_domain: 48 | name: "{{ vultr_dns_domain_name }}" 49 | server_ip: 10.10.10.10 50 | register: result 51 | - name: verify test create dns domain 52 | assert: 53 | that: 54 | - result is changed 55 | - result.vultr_dns_domain.name == '{{ vultr_dns_domain_name }}' 56 | 57 | - name: test create dns domain idempotence 58 | vultr_dns_domain: 59 | name: "{{ vultr_dns_domain_name }}" 60 | server_ip: 10.10.10.10 61 | register: result 62 | - name: verify test create dns domain idempotence 63 | assert: 64 | that: 65 | - result is not changed 66 | - result.vultr_dns_domain.name == '{{ vultr_dns_domain_name }}' 67 | 68 | - name: test absent dns domain in check mode 69 | vultr_dns_domain: 70 | name: "{{ vultr_dns_domain_name }}" 71 | state: absent 72 | register: result 73 | check_mode: yes 74 | - name: verify test absent dns domain in check mode 75 | assert: 76 | that: 77 | - result is changed 78 | - result.vultr_dns_domain.name == '{{ vultr_dns_domain_name }}' 79 | 80 | - name: test absent dns domain 81 | vultr_dns_domain: 82 | name: "{{ vultr_dns_domain_name }}" 83 | state: absent 84 | register: result 85 | - name: verify test absent dns domain 86 | assert: 87 | that: 88 | - result is changed 89 | - result.vultr_dns_domain.name == '{{ vultr_dns_domain_name }}' 90 | 91 | - name: test absent dns domain idempotence 92 | vultr_dns_domain: 93 | name: "{{ vultr_dns_domain_name }}" 94 | state: absent 95 | register: result 96 | - name: verify test absent dns domain idempotence 97 | assert: 98 | that: 99 | - result is not changed 100 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_domain_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_domain_info/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr-test-prefix" 3 | dns_domain_name: "{{ vultr_resource_prefix }}-example-ansible.com" 4 | dns_domain_server_ip: 104.24.16.59 5 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_domain_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: Create the record 5 | vultr_dns_domain: 6 | name: '{{ dns_domain_name }}' 7 | server_ip: '{{ dns_domain_server_ip }}' 8 | 9 | - name: test gather vultr dns domain info in check mode 10 | vultr_dns_domain_info: 11 | check_mode: yes 12 | register: result 13 | 14 | - name: verify test gather vultr dns domain info in check mode 15 | assert: 16 | that: 17 | - result.vultr_dns_domain_info|selectattr('domain','equalto','{{ dns_domain_name }}') | list | count == 1 18 | 19 | - name: test gather vultr dns domain info 20 | vultr_dns_domain_info: 21 | register: result 22 | 23 | - name: verify test gather vultr dns domain info 24 | assert: 25 | that: 26 | - result.vultr_dns_domain_info|selectattr('domain','equalto','{{ dns_domain_name }}') | list | count == 1 27 | 28 | - name: Delete the record 29 | vultr_dns_domain: 30 | name: '{{ dns_domain_name }}' 31 | server_ip: '{{ dns_domain_server_ip }}' 32 | state: absent 33 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_record/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_record/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | vultr_resource_prefix: "vultr-test-prefix" 5 | vultr_dns_domain_name: "{{ vultr_resource_prefix }}-example-ansible.com" 6 | vultr_dns_record_items: 7 | # Single A record 8 | - name: test-www 9 | data: 10.10.10.10 10 | ttl: 400 11 | update_data: 10.10.10.11 12 | update_ttl: 200 13 | 14 | # Multiple A records 15 | - name: test-www-multiple 16 | data: 10.10.11.10 17 | update_data: 10.10.11.11 18 | multiple: true 19 | update_ttl: 600 20 | 21 | # CNAME 22 | - name: test-cname 23 | data: www.ansible.com 24 | update_data: www.ansible.ch 25 | record_type: CNAME 26 | 27 | # Single Multiple MX record 28 | - data: mx1.example-ansible.com 29 | priority: 10 30 | update_priority: 20 31 | record_type: MX 32 | 33 | # Multiple MX records 34 | - data: mx2.example-ansible.com 35 | priority: 10 36 | update_data: mx1.example-ansible.com 37 | update_priority: 20 38 | record_type: MX 39 | multiple: true 40 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_record/tasks/create_record.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test setup dns record 5 | vultr_dns_record: 6 | name: "{{ item.name | default(omit) }}" 7 | domain: "{{ vultr_dns_domain_name }}" 8 | record_type: "{{ item.record_type | default(omit) }}" 9 | state: absent 10 | register: result 11 | - name: verify test setup dns record 12 | assert: 13 | that: 14 | - result is successful 15 | 16 | - name: test create a dns record in check mode 17 | vultr_dns_record: 18 | name: "{{ item.name | default(omit) }}" 19 | domain: "{{ vultr_dns_domain_name }}" 20 | data: "{{ item.data }}" 21 | ttl: "{{ item.ttl | default(omit) }}" 22 | record_type: "{{ item.record_type | default(omit) }}" 23 | priority: "{{ item.priority | default(omit) }}" 24 | check_mode: yes 25 | register: result 26 | - name: verify test create a dns record in check mode 27 | assert: 28 | that: 29 | - result is changed 30 | 31 | - name: test create a dns record 32 | vultr_dns_record: 33 | name: "{{ item.name | default(omit) }}" 34 | domain: "{{ vultr_dns_domain_name }}" 35 | data: "{{ item.data }}" 36 | ttl: "{{ item.ttl | default(omit) }}" 37 | record_type: "{{ item.record_type | default(omit) }}" 38 | priority: "{{ item.priority | default(omit) }}" 39 | register: result 40 | - name: verify test create a dns record 41 | assert: 42 | that: 43 | - result is changed 44 | - result.vultr_dns_record.data == "{{ item.data }}" 45 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 46 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 47 | - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }} 48 | - result.vultr_dns_record.priority == {{ item.priority | default(0) }} 49 | 50 | - name: test create a dns record idempotence 51 | vultr_dns_record: 52 | name: "{{ item.name | default(omit) }}" 53 | domain: "{{ vultr_dns_domain_name }}" 54 | data: "{{ item.data }}" 55 | ttl: "{{ item.ttl | default(omit) }}" 56 | record_type: "{{ item.record_type | default(omit) }}" 57 | priority: "{{ item.priority | default(omit) }}" 58 | register: result 59 | - name: verify test create a dns record idempotence 60 | assert: 61 | that: 62 | - result is not changed 63 | - result.vultr_dns_record.data == "{{ item.data }}" 64 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 65 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 66 | - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }} 67 | - result.vultr_dns_record.priority == {{ item.priority | default(0) }} 68 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_record/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup dns domain 5 | vultr_dns_domain: 6 | name: "{{ vultr_dns_domain_name }}" 7 | server_ip: 10.10.10.10 8 | register: result 9 | - name: verify setup dns domain 10 | assert: 11 | that: 12 | - result is successful 13 | 14 | - include_tasks: test_fail_multiple.yml 15 | 16 | - include_tasks: record.yml 17 | with_items: "{{ vultr_dns_record_items }}" 18 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_record/tasks/record.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - include_tasks: create_record.yml 5 | - include_tasks: update_record.yml 6 | - include_tasks: remove_record.yml 7 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_record/tasks/remove_record.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test remove a dns record in check mode 5 | vultr_dns_record: 6 | name: "{{ item.name | default(omit) }}" 7 | domain: "{{ vultr_dns_domain_name }}" 8 | data: "{{ item.update_data | default(item.data) }}" 9 | record_type: "{{ item.record_type | default(omit) }}" 10 | multiple: "{{ item.multiple | default(omit) }}" 11 | state: absent 12 | check_mode: yes 13 | register: result 14 | - name: verify test remove a dns record in check mode 15 | assert: 16 | that: 17 | - result is changed 18 | - result.vultr_dns_record.data == "{{ item.update_data | default(item.data) }}" 19 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 20 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 21 | - result.vultr_dns_record.ttl == {{ item.update_ttl | default(300) }} 22 | - result.vultr_dns_record.priority == {{ item.update_priority | default(item.priority | default(0)) }} 23 | 24 | - name: test remove second dns record in check mode 25 | vultr_dns_record: 26 | name: "{{ item.name | default(omit) }}" 27 | domain: "{{ vultr_dns_domain_name }}" 28 | data: "{{ item.data | default(item.data) }}" 29 | record_type: "{{ item.record_type | default(omit) }}" 30 | multiple: "{{ item.multiple | default(omit) }}" 31 | state: absent 32 | check_mode: yes 33 | register: result 34 | when: item.multiple is defined and item.multiple == true 35 | - name: verify test remove a dns record in check mode 36 | assert: 37 | that: 38 | - result is changed 39 | - result.vultr_dns_record.data == "{{ item.data | default(item.data) }}" 40 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 41 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 42 | - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }} 43 | - result.vultr_dns_record.priority == {{ item.priority | default(0) }} 44 | when: item.multiple is defined and item.multiple == true 45 | 46 | - name: test remove a dns record 47 | vultr_dns_record: 48 | name: "{{ item.name | default(omit) }}" 49 | domain: "{{ vultr_dns_domain_name }}" 50 | data: "{{ item.update_data | default(item.data) }}" 51 | record_type: "{{ item.record_type | default(omit) }}" 52 | multiple: "{{ item.multiple | default(omit) }}" 53 | state: absent 54 | register: result 55 | - name: verify test remove a dns record 56 | assert: 57 | that: 58 | - result is changed 59 | - result.vultr_dns_record.data == "{{ item.update_data | default(item.data) }}" 60 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 61 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 62 | - result.vultr_dns_record.ttl == {{ item.update_ttl | default(300) }} 63 | - result.vultr_dns_record.priority == {{ item.update_priority | default(item.priority | default(0)) }} 64 | 65 | - name: test remove second dns record 66 | vultr_dns_record: 67 | name: "{{ item.name | default(omit) }}" 68 | domain: "{{ vultr_dns_domain_name }}" 69 | data: "{{ item.data }}" 70 | record_type: "{{ item.record_type | default(omit) }}" 71 | multiple: "{{ item.multiple | default(omit) }}" 72 | state: absent 73 | register: result 74 | when: item.multiple is defined and item.multiple == true 75 | - name: verify test remove a dns record 76 | assert: 77 | that: 78 | - result is changed 79 | - result.vultr_dns_record.data == "{{ item.data }}" 80 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 81 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 82 | - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }} 83 | - result.vultr_dns_record.priority == {{ item.priority | default(0) }} 84 | when: item.multiple is defined and item.multiple == true 85 | 86 | - name: test remove a dns record idempotence 87 | vultr_dns_record: 88 | name: "{{ item.name | default(omit) }}" 89 | domain: "{{ vultr_dns_domain_name }}" 90 | data: "{{ item.update_data | default(item.data) }}" 91 | record_type: "{{ item.record_type | default(omit) }}" 92 | multiple: "{{ item.multiple | default(omit) }}" 93 | state: absent 94 | register: result 95 | - name: verify test remove a dns record idempotence 96 | assert: 97 | that: 98 | - result is not changed 99 | 100 | - name: test remove second dns record idempotence 101 | vultr_dns_record: 102 | name: "{{ item.name | default(omit) }}" 103 | domain: "{{ vultr_dns_domain_name }}" 104 | data: "{{ item.data }}" 105 | record_type: "{{ item.record_type | default(omit) }}" 106 | multiple: "{{ item.multiple | default(omit) }}" 107 | state: absent 108 | register: result 109 | when: item.multiple is defined and item.multiple == true 110 | - name: verify test remove a dns record idempotence 111 | assert: 112 | that: 113 | - result is not changed 114 | when: item.multiple is defined and item.multiple == true 115 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_record/tasks/test_fail_multiple.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup first dns record 5 | vultr_dns_record: 6 | name: test-multiple 7 | domain: "{{ vultr_dns_domain_name }}" 8 | data: 1.2.3.4 9 | multiple: yes 10 | register: result 11 | - name: verify setup a dns record 12 | assert: 13 | that: 14 | - result is successful 15 | 16 | - name: setup second dns record 17 | vultr_dns_record: 18 | name: test-multiple 19 | domain: "{{ vultr_dns_domain_name }}" 20 | data: 1.2.3.5 21 | multiple: yes 22 | register: result 23 | - name: verify setup second dns record 24 | assert: 25 | that: 26 | - result is successful 27 | 28 | - name: test-multiple fail multiple identical records found 29 | vultr_dns_record: 30 | name: test-multiple 31 | domain: "{{ vultr_dns_domain_name }}" 32 | state: absent 33 | register: result 34 | ignore_errors: yes 35 | - name: verify test fail multiple identical records found 36 | assert: 37 | that: 38 | - result is failed 39 | 40 | - name: test-multiple fail absent multiple identical records but not data 41 | vultr_dns_record: 42 | name: test-multiple 43 | domain: "{{ vultr_dns_domain_name }}" 44 | state: absent 45 | multiple: yes 46 | register: result 47 | ignore_errors: yes 48 | - name: verify test-multiple success absent multiple identical records found 49 | assert: 50 | that: 51 | - result is failed 52 | - "result.msg == 'multiple is True but all of the following are missing: data'" 53 | 54 | - name: test-multiple success absent multiple identical records second found 55 | vultr_dns_record: 56 | name: test-multiple 57 | domain: "{{ vultr_dns_domain_name }}" 58 | data: 1.2.3.5 59 | state: absent 60 | multiple: yes 61 | register: result 62 | - name: verify test-multiple success absent multiple identical records second found 63 | assert: 64 | that: 65 | - result is changed 66 | 67 | - name: test-multiple success absent multiple identical records first found 68 | vultr_dns_record: 69 | name: test-multiple 70 | domain: "{{ vultr_dns_domain_name }}" 71 | data: 1.2.3.4 72 | state: absent 73 | multiple: yes 74 | register: result 75 | - name: verify test-multiple success absent multiple identical records firstfound 76 | assert: 77 | that: 78 | - result is changed 79 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_dns_record/tasks/update_record.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test update or add another dns record in check mode 5 | vultr_dns_record: 6 | name: "{{ item.name | default(omit) }}" 7 | domain: "{{ vultr_dns_domain_name }}" 8 | data: "{{ item.update_data | default(item.data) }}" 9 | ttl: "{{ item.update_ttl | default(omit) }}" 10 | record_type: "{{ item.record_type | default(omit) }}" 11 | priority: "{{ item.update_priority | default(omit) }}" 12 | multiple: "{{ item.multiple | default(omit) }}" 13 | check_mode: yes 14 | register: result 15 | - name: verify test updatein check mode 16 | assert: 17 | that: 18 | - result is changed 19 | - result.vultr_dns_record.data == "{{ item.data }}" 20 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 21 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 22 | - result.vultr_dns_record.ttl == {{ item.ttl | default(300) }} 23 | - result.vultr_dns_record.priority == {{ item.priority | default(0) }} 24 | when: item.multiple is undefined or item.multiple == false 25 | - name: verify test add another dns record in check mode 26 | assert: 27 | that: 28 | - result is changed 29 | - not result.vultr_dns_record 30 | when: item.multiple is defined and item.multiple == true 31 | 32 | - name: test update or add another dns record 33 | vultr_dns_record: 34 | name: "{{ item.name | default(omit) }}" 35 | domain: "{{ vultr_dns_domain_name }}" 36 | data: "{{ item.update_data | default(item.data) }}" 37 | ttl: "{{ item.update_ttl | default(omit) }}" 38 | record_type: "{{ item.record_type | default(omit) }}" 39 | priority: "{{ item.update_priority | default(omit) }}" 40 | multiple: "{{ item.multiple | default(omit) }}" 41 | register: result 42 | - name: verify test update a dns record 43 | assert: 44 | that: 45 | - result is changed 46 | - result.vultr_dns_record.data == "{{ item.update_data | default(item.data) }}" 47 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 48 | - result.vultr_dns_record.ttl == {{ item.update_ttl | default(300) }} 49 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 50 | - result.vultr_dns_record.priority == {{ item.update_priority | default(0) }} 51 | 52 | - name: test update or add another dns record idempotence 53 | vultr_dns_record: 54 | name: "{{ item.name | default(omit) }}" 55 | domain: "{{ vultr_dns_domain_name }}" 56 | data: "{{ item.update_data | default(item.data) }}" 57 | ttl: "{{ item.update_ttl | default(omit) }}" 58 | record_type: "{{ item.record_type | default(omit) }}" 59 | priority: "{{ item.update_priority | default(omit) }}" 60 | multiple: "{{ item.multiple | default(omit) }}" 61 | register: result 62 | - name: verify test update a dns record idempotence 63 | assert: 64 | that: 65 | - result is not changed 66 | - result.vultr_dns_record.data == "{{ item.update_data | default(item.data) }}" 67 | - result.vultr_dns_record.name == "{{ item.name | default("") }}" 68 | - result.vultr_dns_record.ttl == {{ item.update_ttl | default(300) }} 69 | - result.vultr_dns_record.record_type == "{{ item.record_type | default('A') }}" 70 | - result.vultr_dns_record.priority == {{ item.update_priority | default(0) }} 71 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_firewall_group/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_firewall_group/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | vultr_resource_prefix: "vultr-test-prefix" 5 | vultr_firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group" 6 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_firewall_group/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup 5 | vultr_firewall_group: 6 | name: "{{ vultr_firewall_group_name }}" 7 | state: absent 8 | register: result 9 | - name: verify setup 10 | assert: 11 | that: 12 | - result is success 13 | 14 | - name: test fail if missing name 15 | vultr_firewall_group: 16 | register: result 17 | ignore_errors: yes 18 | - name: verify test fail if missing name 19 | assert: 20 | that: 21 | - result is failed 22 | - 'result.msg == "missing required arguments: name"' 23 | 24 | - name: test create firewall group in check mode 25 | vultr_firewall_group: 26 | name: "{{ vultr_firewall_group_name }}" 27 | register: result 28 | check_mode: yes 29 | - name: verify test create firewall group in check mode 30 | assert: 31 | that: 32 | - result is changed 33 | 34 | - name: test create firewall group 35 | vultr_firewall_group: 36 | name: "{{ vultr_firewall_group_name }}" 37 | register: result 38 | - name: verify test create firewall group 39 | assert: 40 | that: 41 | - result is changed 42 | - result.vultr_firewall_group.name == '{{ vultr_firewall_group_name }}' 43 | 44 | - name: test create firewall group idempotence 45 | vultr_firewall_group: 46 | name: "{{ vultr_firewall_group_name }}" 47 | 48 | register: result 49 | - name: verify test create firewall group idempotence 50 | assert: 51 | that: 52 | - result is not changed 53 | - result.vultr_firewall_group.name == '{{ vultr_firewall_group_name }}' 54 | 55 | - name: test absent firewall group in check mode 56 | vultr_firewall_group: 57 | name: "{{ vultr_firewall_group_name }}" 58 | state: absent 59 | register: result 60 | check_mode: yes 61 | - name: verify test absent firewall group in check mode 62 | assert: 63 | that: 64 | - result is changed 65 | - result.vultr_firewall_group.name == '{{ vultr_firewall_group_name }}' 66 | 67 | - name: test absent firewall group 68 | vultr_firewall_group: 69 | name: "{{ vultr_firewall_group_name }}" 70 | state: absent 71 | register: result 72 | - name: verify test absent firewall group 73 | assert: 74 | that: 75 | - result is changed 76 | - result.vultr_firewall_group.name == '{{ vultr_firewall_group_name }}' 77 | 78 | - name: test absent firewall group idempotence 79 | vultr_firewall_group: 80 | name: "{{ vultr_firewall_group_name }}" 81 | state: absent 82 | register: result 83 | - name: verify test absent firewall group idempotence 84 | assert: 85 | that: 86 | - result is not changed 87 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_firewall_group_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_firewall_group_info/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr-test-prefix" 3 | firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group" 4 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_firewall_group_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test gather vultr firewall group info - empty resources 5 | vultr_firewall_group_info: 6 | 7 | - name: Create the firewall group 8 | vultr_firewall_group: 9 | name: '{{ firewall_group_name }}' 10 | 11 | - name: test gather vultr firewall group info in check mode 12 | vultr_firewall_group_info: 13 | check_mode: yes 14 | register: result 15 | 16 | - name: verify test gather vultr firewall group info in check mode 17 | assert: 18 | that: 19 | - result.vultr_firewall_group_info|selectattr('description','equalto','{{ firewall_group_name }}') | list | count == 1 20 | 21 | - name: test gather vultr firewall group info 22 | vultr_firewall_group_info: 23 | register: result 24 | 25 | - name: verify test gather vultr firewall group info 26 | assert: 27 | that: 28 | - result.vultr_firewall_group_info|selectattr('description','equalto','{{ firewall_group_name }}') | list | count == 1 29 | 30 | - name: Delete the firewall group 31 | vultr_firewall_group: 32 | name: '{{ firewall_group_name }}' 33 | state: absent 34 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_firewall_rule/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_firewall_rule/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | vultr_resource_prefix: "vultr-test-prefix" 5 | vultr_firewall_group_name: "{{ vultr_resource_prefix }}_firewall-group" 6 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_network/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_network/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr-test-prefix" 3 | vultr_network_name: "{{ vultr_resource_prefix }}_network" 4 | vultr_network_cidr: 192.168.42.0/24 5 | vultr_network_region: New Jersey 6 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_network/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup 5 | vultr_network: 6 | name: "{{ vultr_network_name }}" 7 | state: absent 8 | register: result 9 | - name: verify setup 10 | assert: 11 | that: 12 | - result is success 13 | 14 | - name: test fail if missing name 15 | vultr_network: 16 | register: result 17 | ignore_errors: yes 18 | - name: verify test fail if missing name 19 | assert: 20 | that: 21 | - result is failed 22 | - 'result.msg == "missing required arguments: name"' 23 | 24 | - name: test fail if missing params for state=present 25 | vultr_network: 26 | name: "{{ vultr_network_name }}" 27 | register: result 28 | ignore_errors: yes 29 | - name: verify fail if missing params for state=present 30 | assert: 31 | that: 32 | - result is failed 33 | - 'result.msg == "state is present but all of the following are missing: cidr, region"' 34 | 35 | - name: test create network in check mode 36 | vultr_network: 37 | name: "{{ vultr_network_name }}" 38 | cidr: "{{ vultr_network_cidr }}" 39 | region: "{{ vultr_network_region }}" 40 | register: result 41 | check_mode: yes 42 | - name: verify test create server in check mode 43 | assert: 44 | that: 45 | - result is changed 46 | 47 | - name: test create network 48 | vultr_network: 49 | name: "{{ vultr_network_name }}" 50 | cidr: "{{ vultr_network_cidr }}" 51 | region: "{{ vultr_network_region }}" 52 | register: result 53 | 54 | - name: verify test create network 55 | assert: 56 | that: 57 | - result is changed 58 | - result.vultr_network.name == "{{ vultr_network_name }}" 59 | - result.vultr_network.region == "{{ vultr_network_region }}" 60 | - result.vultr_network.v4_subnet == "{{ vultr_network_cidr.split('/')[0] }}" 61 | - result.vultr_network.v4_subnet_mask == 24 62 | 63 | - name: test create network idempotence 64 | vultr_network: 65 | name: "{{ vultr_network_name }}" 66 | cidr: "{{ vultr_network_cidr }}" 67 | region: "{{ vultr_network_region }}" 68 | register: result 69 | 70 | - name: verify test network idempotence 71 | assert: 72 | that: 73 | - result is not changed 74 | - result.vultr_network.name == "{{ vultr_network_name }}" 75 | - result.vultr_network.region == "{{ vultr_network_region }}" 76 | - result.vultr_network.v4_subnet == "{{ vultr_network_cidr.split('/')[0] }}" 77 | - result.vultr_network.v4_subnet_mask == 24 78 | 79 | - name: test destroy network in check mode 80 | vultr_network: 81 | name: "{{ vultr_network_name }}" 82 | state: absent 83 | register: result 84 | check_mode: yes 85 | 86 | - name: verify test destroy network in check mode 87 | assert: 88 | that: 89 | - result is changed 90 | - result.vultr_network.name == "{{ vultr_network_name }}" 91 | 92 | - name: test destroy network volume 93 | vultr_network: 94 | name: "{{ vultr_network_name }}" 95 | state: absent 96 | register: result 97 | 98 | - name: verify test destroy an existing network 99 | assert: 100 | that: 101 | - result is changed 102 | - result.vultr_network.name == "{{ vultr_network_name }}" 103 | 104 | - name: test destroy an existing network idempotence 105 | vultr_network: 106 | name: "{{ vultr_network_name }}" 107 | state: absent 108 | register: result 109 | 110 | - name: verify test destroy an existing network idempotence 111 | assert: 112 | that: 113 | - result is not changed 114 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_network_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_network_info/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr_test_prefix" 3 | vultr_network_name: "{{ vultr_resource_prefix }}_network" 4 | vultr_network_cidr: 192.168.42.0/24 5 | vultr_network_region: New Jersey 6 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_network_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test gather vultr network info - empty resources 5 | vultr_network_info: 6 | 7 | - name: Create the network 8 | vultr_network: 9 | name: '{{ vultr_network_name }}' 10 | cidr: '{{ vultr_network_cidr }}' 11 | region: '{{ vultr_network_region }}' 12 | 13 | - name: test gather vultr network info in check mode 14 | vultr_network_info: 15 | check_mode: yes 16 | register: result 17 | 18 | - name: verify test gather vultr network info in check mode 19 | assert: 20 | that: 21 | - result.vultr_network_info|selectattr('name','equalto','{{ vultr_network_name }}') | list | count == 1 22 | 23 | - name: test gather vultr network info 24 | vultr_network_info: 25 | register: result 26 | 27 | - name: verify test gather vultr network info 28 | assert: 29 | that: 30 | - result.vultr_network_info|selectattr('name','equalto','{{ vultr_network_name }}') | list | count == 1 31 | 32 | - name: Delete the script 33 | vultr_network: 34 | name: '{{ vultr_network_name }}' 35 | state: absent 36 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_os_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_os_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # Copyright (c) 2019, René Moser 3 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 4 | --- 5 | - name: test get vultr os infos in check mode 6 | vultr_os_info: 7 | check_mode: yes 8 | register: result 9 | 10 | - name: verify test get vultr os infos in check mode 11 | assert: 12 | that: 13 | - result.vultr_os_info|selectattr('name','equalto', 'CentOS 7 x64') | list | count == 1 14 | 15 | - name: test get vultr os fact 16 | vultr_os_info: 17 | register: result 18 | 19 | - name: verify test get vultr os infos 20 | assert: 21 | that: 22 | - result.vultr_os_info|selectattr('name','equalto', 'CentOS 7 x64') | list | count == 1 23 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_plan_baremetal_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_plan_baremetal_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # Copyright (c) 2020, Simon Bärlocher 3 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 4 | --- 5 | - name: test gather vultr plan baremetal info in check mode 6 | vultr_plan_baremetal_info: 7 | check_mode: yes 8 | register: result 9 | 10 | - name: verify test gather vultr plan baremetal info in check mode 11 | assert: 12 | that: 13 | - result.vultr_plan_baremetal_info|selectattr('name','equalto','65536 MB RAM,2x 240 GB SSD,5.00 TB BW') | list | count == 1 14 | 15 | - name: test gather vultr plan baremetal info 16 | vultr_plan_baremetal_info: 17 | register: result 18 | 19 | - name: verify test gather vultr plan baremetal info 20 | assert: 21 | that: 22 | - result.vultr_plan_baremetal_info|selectattr('name','equalto','65536 MB RAM,2x 240 GB SSD,5.00 TB BW') | list | count == 1 23 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_plan_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_plan_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test gather vultr plan info in check mode 5 | vultr_plan_info: 6 | check_mode: yes 7 | register: result 8 | 9 | - name: verify test gather vultr plan info in check mode 10 | assert: 11 | that: 12 | - result.vultr_plan_info|selectattr('name','equalto','16384 MB RAM,2x110 GB SSD,20.00 TB BW') | list | count == 1 13 | 14 | - name: test gather vultr plan info 15 | vultr_plan_info: 16 | register: result 17 | 18 | - name: verify test gather vultr plan info 19 | assert: 20 | that: 21 | - result.vultr_plan_info|selectattr('name','equalto','16384 MB RAM,2x110 GB SSD,20.00 TB BW') | list | count == 1 22 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_region_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_region_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test gather vultr region info in check mode 5 | vultr_region_info: 6 | check_mode: yes 7 | register: result 8 | 9 | - name: verify test gather vultr region info in check mode 10 | assert: 11 | that: 12 | - result.vultr_region_info|selectattr('name','equalto','Atlanta') | list | count == 1 13 | 14 | - name: test gather vultr region info 15 | vultr_region_info: 16 | register: result 17 | 18 | - name: verify test gather vultr region info 19 | assert: 20 | that: 21 | - result.vultr_region_info|selectattr('name','equalto','Atlanta') | list | count == 1 22 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_server/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_server/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | vultr_resource_prefix: "vultr-test-prefix" 5 | vultr_server_name: "{{ vultr_resource_prefix }}_vm" 6 | vultr_server_ssh_keys: 7 | - name: key1 8 | key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= mail@renemoser.net" 9 | - name: key2 10 | key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoQ9S7V+CufAgwoehnf2TqsJ9LTsu8pUA3FgpS2mdVwcMcTs++8P5sQcXHLtDmNLpWN4k7NQgxaY1oXy5e25x/4VhXaJXWEt3luSw+Phv/PB2+aGLvqCUirsLTAD2r7ieMhd/pcVf/HlhNUQgnO1mupdbDyqZoGD/uCcJiYav8i/V7nJWJouHA8yq31XS2yqXp9m3VC7UZZHzUsVJA9Us5YqF0hKYeaGruIHR2bwoDF9ZFMss5t6/pzxMljU/ccYwvvRDdI7WX4o4+zLuZ6RWvsU6LGbbb0pQdB72tlV41fSefwFsk4JRdKbyV3Xjf25pV4IXOTcqhy+4JTB/jXxrF torwalds@github.com" 11 | 12 | vultr_server_plan_1: 1024 MB RAM,25 GB SSD,1.00 TB BW 13 | vultr_server_plan_2: 2048 MB RAM,55 GB SSD,2.00 TB BW 14 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_server_baremetal/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_server_baremetal/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # Copyright (c) 2020, Simon Bärlocher 3 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 4 | --- 5 | vultr_resource_prefix: 'vultr-test-prefix' 6 | vultr_server_baremetal_name: '{{ vultr_resource_prefix }}_baremetal' 7 | vultr_server_baremetal_ssh_keys: 8 | - name: key1 9 | key: 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= mail@renemoser.net' 10 | - name: key2 11 | key: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoQ9S7V+CufAgwoehnf2TqsJ9LTsu8pUA3FgpS2mdVwcMcTs++8P5sQcXHLtDmNLpWN4k7NQgxaY1oXy5e25x/4VhXaJXWEt3luSw+Phv/PB2+aGLvqCUirsLTAD2r7ieMhd/pcVf/HlhNUQgnO1mupdbDyqZoGD/uCcJiYav8i/V7nJWJouHA8yq31XS2yqXp9m3VC7UZZHzUsVJA9Us5YqF0hKYeaGruIHR2bwoDF9ZFMss5t6/pzxMljU/ccYwvvRDdI7WX4o4+zLuZ6RWvsU6LGbbb0pQdB72tlV41fSefwFsk4JRdKbyV3Xjf25pV4IXOTcqhy+4JTB/jXxrF torwalds@github.com' 12 | 13 | vultr_server_baremetal_plan_1: 65536 MB RAM,2x 240 GB SSD,5.00 TB BW 14 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_server_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_server_info/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr-test-prefix" 3 | vultr_server_name: "{{ vultr_resource_prefix }}_vm" 4 | vultr_server_os: CentOS 7 x64 5 | vultr_server_plan: 1024 MB RAM,25 GB SSD,1.00 TB BW 6 | vultr_server_region: Amsterdam 7 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_server_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup ensure VM is absent 5 | vultr_server: 6 | name: "{{ vultr_server_name }}" 7 | state: absent 8 | register: result 9 | 10 | # Servers can only be destroyed 5 min after creation 11 | - name: wait for 5 min until VM is absent 12 | wait_for: 13 | when: result is changed 14 | 15 | - name: test gather vultr server info - empty resources 16 | vultr_server_info: 17 | register: result 18 | - name: verify test gather vultr server info - empty resources 19 | assert: 20 | that: 21 | - result.vultr_server_info | selectattr('name','equalto',vultr_server_name) | list | count == 0 22 | 23 | - name: setup firewall group 24 | vultr_firewall_group: 25 | name: test_vultr_server_info 26 | 27 | - name: setup create the server 28 | vultr_server: 29 | name: '{{ vultr_server_name }}' 30 | os: '{{ vultr_server_os }}' 31 | plan: '{{ vultr_server_plan }}' 32 | region: '{{ vultr_server_region }}' 33 | firewall_group: test_vultr_server_info 34 | 35 | - name: test gather vultr server info in check mode 36 | vultr_server_info: 37 | check_mode: yes 38 | register: result 39 | 40 | - name: verify test gather vultr server info in check mode 41 | assert: 42 | that: 43 | - result.vultr_server_info|selectattr('name','equalto',vultr_server_name) | list | count == 1 44 | 45 | - name: test gather vultr server info 46 | vultr_server_info: 47 | register: result 48 | 49 | - name: verify test gather vultr server info 50 | assert: 51 | that: 52 | - result.vultr_server_info|selectattr('name','equalto',vultr_server_name) | list | count == 1 53 | 54 | - name: Pause for 5 min before deleting the VM 55 | pause: 56 | minutes: 5 57 | 58 | - name: cleanup the server 59 | vultr_server: 60 | name: '{{ vultr_server_name }}' 61 | state: absent 62 | 63 | - name: cleanup firewall group 64 | vultr_firewall_group: 65 | name: test_vultr_server_info 66 | state: absent 67 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_ssh_key/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_ssh_key/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | vultr_resource_prefix: "vultr-test-prefix" 5 | vultr_ssh_key_name: "{{ vultr_resource_prefix }}_ansible-ssh-key" 6 | vultr_ssh_key: "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAgEAyWYItY+3w5b8PdGRoz0oY5mufqydW96naE+VM3JSvJFAUS08rAjQQpQ03ymoALeHQy6JVZbcgecxn6p0pAOINQdqufn4udPtOPCtMjNiPGpkSM9ah/6X5+kvyWMNrvlf+Ld4OOoszP5sAkgQzIbrFQAm41XknBUha0zkewZwfrVhain4pnDjV7wCcChId/Q/Gbi4xMtXkisznWcAJcueBs3EEZDKhJ5q0VeWSJEhYJDLFN1sOxF0AIUnMrOhfKQ/LjgREXPB6uCl899INUTXRNNjRpeMXyJ2wMMmOAbua2qEd1r13Bu1n+6A823Hzb33fyMXuqWnJwBJ4DCvMlGuEsfuOK+xk7DaBfLHbcM6fsPk0/4psTE6YLgC41remr6+u5ZWsY/faMtSnNPie8Z8Ov0DIYGdhbJjUXk1HomxRV9+ZfZ2Ob8iCwlaAQAyEUM6fs3Kxt8pBD8dx1HOkhsfBWPvuDr5y+kqE7H8/MuPDTc0QgH2pjUMpmw/XBwNDHshVEjrZvtICOjOLUJxcowLO1ivNYwPwowQxfisMy56LfYdjsOslBiqsrkAqvNGm1zu8wKHeqVN9w5l3yUELpvubfm9NKIvYcl6yWF36T0c5vE+g0DU/Jy4XpTj0hZG9QV2mRQcLJnd2pxQtJT7cPFtrn/+tgRxzjEtbDXummDV4sE= ansible@example.com" 7 | vultr_ssh_key2: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoQ9S7V+CufAgwoehnf2TqsJ9LTsu8pUA3FgpS2mdVwcMcTs++8P5sQcXHLtDmNLpWN4k7NQgxaY1oXy5e25x/4VhXaJXWEt3luSw+Phv/PB2+aGLvqCUirsLTAD2r7ieMhd/pcVf/HlhNUQgnO1mupdbDyqZoGD/uCcJiYav8i/V7nJWJouHA8yq31XS2yqXp9m3VC7UZZHzUsVJA9Us5YqF0hKYeaGruIHR2bwoDF9ZFMss5t6/pzxMljU/ccYwvvRDdI7WX4o4+zLuZ6RWvsU6LGbbb0pQdB72tlV41fSefwFsk4JRdKbyV3Xjf25pV4IXOTcqhy+4JTB/jXxrF torwalds@github.com" 8 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_ssh_key/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup 5 | vultr_ssh_key: 6 | name: "{{ vultr_ssh_key_name }}" 7 | state: absent 8 | register: result 9 | - name: verify setup 10 | assert: 11 | that: 12 | - result is success 13 | 14 | - name: test fail if missing name 15 | vultr_ssh_key: 16 | register: result 17 | ignore_errors: yes 18 | - name: verify test fail if missing name 19 | assert: 20 | that: 21 | - result is failed 22 | - 'result.msg == "missing required arguments: name"' 23 | 24 | - name: test fail if missing params for state=present 25 | vultr_ssh_key: 26 | name: "{{ vultr_ssh_key_name }}" 27 | register: result 28 | ignore_errors: yes 29 | - name: verify fail if missing params for state=present 30 | assert: 31 | that: 32 | - result is failed 33 | - 'result.msg == "state is present but all of the following are missing: ssh_key"' 34 | 35 | - name: test create ssh key in check mode 36 | vultr_ssh_key: 37 | name: "{{ vultr_ssh_key_name }}" 38 | ssh_key: "{{ vultr_ssh_key }}" 39 | register: result 40 | check_mode: yes 41 | - name: verify test create ssh key in check mode 42 | assert: 43 | that: 44 | - result is changed 45 | 46 | - name: test create ssh key 47 | vultr_ssh_key: 48 | name: "{{ vultr_ssh_key_name }}" 49 | ssh_key: "{{ vultr_ssh_key }}" 50 | register: result 51 | - name: verify test create ssh key 52 | assert: 53 | that: 54 | - result is changed 55 | - result.vultr_ssh_key.name == '{{ vultr_ssh_key_name }}' 56 | - result.vultr_ssh_key.ssh_key == '{{ vultr_ssh_key }}' 57 | 58 | - name: test create ssh key idempotence 59 | vultr_ssh_key: 60 | name: "{{ vultr_ssh_key_name }}" 61 | ssh_key: "{{ vultr_ssh_key }}" 62 | register: result 63 | - name: verify test create ssh key idempotence 64 | assert: 65 | that: 66 | - result is not changed 67 | - result.vultr_ssh_key.name == '{{ vultr_ssh_key_name }}' 68 | - result.vultr_ssh_key.ssh_key == '{{ vultr_ssh_key }}' 69 | 70 | - name: test update ssh key in check mode 71 | vultr_ssh_key: 72 | name: "{{ vultr_ssh_key_name }}" 73 | ssh_key: "{{ vultr_ssh_key2 }}" 74 | register: result 75 | check_mode: yes 76 | - name: verify test update ssh key in check mode 77 | assert: 78 | that: 79 | - result is changed 80 | - result.vultr_ssh_key.name == '{{ vultr_ssh_key_name }}' 81 | - result.vultr_ssh_key.ssh_key == '{{ vultr_ssh_key }}' 82 | 83 | - name: test update ssh key 84 | vultr_ssh_key: 85 | name: "{{ vultr_ssh_key_name }}" 86 | ssh_key: "{{ vultr_ssh_key2 }}" 87 | register: result 88 | - name: verify test update ssh key 89 | assert: 90 | that: 91 | - result is changed 92 | - result.vultr_ssh_key.name == '{{ vultr_ssh_key_name }}' 93 | - result.vultr_ssh_key.ssh_key == '{{ vultr_ssh_key2 }}' 94 | 95 | - name: test update ssh key idempotence 96 | vultr_ssh_key: 97 | name: "{{ vultr_ssh_key_name }}" 98 | ssh_key: "{{ vultr_ssh_key2 }}" 99 | register: result 100 | - name: verify test update ssh key idempotence 101 | assert: 102 | that: 103 | - result is not changed 104 | - result.vultr_ssh_key.name == '{{ vultr_ssh_key_name }}' 105 | - result.vultr_ssh_key.ssh_key == '{{ vultr_ssh_key2 }}' 106 | 107 | - name: test absent ssh key in check mode 108 | vultr_ssh_key: 109 | name: "{{ vultr_ssh_key_name }}" 110 | state: absent 111 | register: result 112 | check_mode: yes 113 | - name: verify test absent ssh key in check mode 114 | assert: 115 | that: 116 | - result is changed 117 | - result.vultr_ssh_key.name == '{{ vultr_ssh_key_name }}' 118 | - result.vultr_ssh_key.ssh_key == '{{ vultr_ssh_key2 }}' 119 | 120 | - name: test absent ssh key 121 | vultr_ssh_key: 122 | name: "{{ vultr_ssh_key_name }}" 123 | state: absent 124 | register: result 125 | - name: verify test absent ssh key 126 | assert: 127 | that: 128 | - result is changed 129 | - result.vultr_ssh_key.name == '{{ vultr_ssh_key_name }}' 130 | - result.vultr_ssh_key.ssh_key == '{{ vultr_ssh_key2 }}' 131 | 132 | - name: test absent ssh key idempotence 133 | vultr_ssh_key: 134 | name: "{{ vultr_ssh_key_name }}" 135 | state: absent 136 | register: result 137 | - name: verify test absent ssh key idempotence 138 | assert: 139 | that: 140 | - result is not changed 141 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_ssh_key_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_ssh_key_info/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr_test_prefix" 3 | ssh_key_name: "{{ vultr_resource_prefix }}-sshkey" 4 | ssh_key_content: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC+ZFQv3MyjtL1BMpSA0o0gIkzLVVC711rthT29hBNeORdNowQ7FSvVWUdAbTq00U7Xzak1ANIYLJyn+0r7olsdG4XEiUR0dqgC99kbT/QhY5mLe5lpl7JUjW9ctn00hNmt+TswpatCKWPNwdeAJT2ERynZaqPobENgvIq7jfOFWQIVew7qrewtqwerqwrewUr2Cdq7Nb7U0XFXh3x1p0v0+MbL4tiJwPlMAGvFTKIMt+EaA+AsRIxiOo9CMk5ZuOl9pT8h5vNuEOcvS0qx4v44EAD2VOsCVCcrPNMcpuSzZP8dRTGU9wRREAWXngD0Zq9YJMH38VTxHiskoBw1NnPz ansibletest-{{ vultr_resource_prefix }}@sshkey 5 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_ssh_key_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # Copyright (c) 2019, René Moser 3 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 4 | --- 5 | - name: test get vultr ssh key info - empty resources 6 | vultr_ssh_key_info: 7 | register: result 8 | 9 | - name: verify test get vultr ssh key infos in check mode 10 | assert: 11 | that: 12 | - result.vultr_ssh_key_info|selectattr('name','equalto','{{ ssh_key_name }}') | list | count == 0 13 | - result.vultr_ssh_key_info|selectattr('ssh_key','equalto','{{ ssh_key_content }}') | list | count == 0 14 | 15 | - name: Upload an ssh key 16 | vultr_ssh_key: 17 | name: '{{ ssh_key_name }}' 18 | ssh_key: '{{ ssh_key_content }}' 19 | 20 | - name: test get vultr ssh key infos in check mode 21 | vultr_ssh_key_info: 22 | check_mode: yes 23 | register: result 24 | 25 | - name: verify test get vultr ssh key infos in check mode 26 | assert: 27 | that: 28 | - result.vultr_ssh_key_info|selectattr('name','equalto','{{ ssh_key_name }}') | list | count == 1 29 | - result.vultr_ssh_key_info|selectattr('ssh_key','equalto','{{ ssh_key_content }}') | list | count == 1 30 | 31 | - name: test get vultr ssh key info 32 | vultr_ssh_key_info: 33 | register: result 34 | 35 | - name: verify test get vultr ssh key infos 36 | assert: 37 | that: 38 | - result.vultr_ssh_key_info|selectattr('name','equalto','{{ ssh_key_name }}') | list | count == 1 39 | - result.vultr_ssh_key_info|selectattr('ssh_key','equalto','{{ ssh_key_content }}') | list | count == 1 40 | 41 | - name: Destroy the ssh key 42 | vultr_ssh_key: 43 | name: '{{ ssh_key_name }}' 44 | state: absent 45 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_startup_script/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_startup_script/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | vultr_resource_prefix: "vultr-test-prefix" 5 | vultr_startup_script_name: "{{ vultr_resource_prefix }}_script" 6 | vultr_startup_script: "#!/bin/bash\necho Hello World > /root/hello" 7 | vultr_startup_script2: "#!/bin/bash\necho Hello to my World > /root/hello" 8 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_startup_script/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: setup 5 | vultr_startup_script: 6 | name: "{{ vultr_startup_script_name }}" 7 | state: absent 8 | register: result 9 | - name: verify setup 10 | assert: 11 | that: 12 | - result is success 13 | 14 | - name: test fail if missing name 15 | vultr_startup_script: 16 | register: result 17 | ignore_errors: yes 18 | - name: verify test fail if missing name 19 | assert: 20 | that: 21 | - result is failed 22 | - 'result.msg == "missing required arguments: name"' 23 | 24 | - name: test fail if missing params for state=present 25 | vultr_startup_script: 26 | name: "{{ vultr_startup_script_name }}" 27 | register: result 28 | ignore_errors: yes 29 | - name: verify fail if missing params for state=present 30 | assert: 31 | that: 32 | - result is failed 33 | - 'result.msg == "state is present but all of the following are missing: script"' 34 | 35 | - name: test create startup script in check mode 36 | vultr_startup_script: 37 | name: "{{ vultr_startup_script_name }}" 38 | script: "{{ vultr_startup_script }}" 39 | register: result 40 | check_mode: yes 41 | - name: verify test create startup script in check mode 42 | assert: 43 | that: 44 | - result is changed 45 | 46 | - name: test create startup script 47 | vultr_startup_script: 48 | name: "{{ vultr_startup_script_name }}" 49 | script: "{{ vultr_startup_script }}" 50 | register: result 51 | - name: verify test create startup script 52 | assert: 53 | that: 54 | - result is changed 55 | - result.vultr_startup_script.name == '{{ vultr_startup_script_name }}' 56 | - result.vultr_startup_script.script == '{{ vultr_startup_script }}' 57 | 58 | - name: test create startup script idempotence 59 | vultr_startup_script: 60 | name: "{{ vultr_startup_script_name }}" 61 | script: "{{ vultr_startup_script }}" 62 | register: result 63 | - name: verify test create startup script idempotence 64 | assert: 65 | that: 66 | - result is not changed 67 | - result.vultr_startup_script.name == '{{ vultr_startup_script_name }}' 68 | - result.vultr_startup_script.script == '{{ vultr_startup_script }}' 69 | 70 | - name: test update startup script in check mode 71 | vultr_startup_script: 72 | name: "{{ vultr_startup_script_name }}" 73 | script: "{{ vultr_startup_script2 }}" 74 | register: result 75 | check_mode: yes 76 | - name: verify test update startup script in check mode 77 | assert: 78 | that: 79 | - result is changed 80 | - result.vultr_startup_script.name == '{{ vultr_startup_script_name }}' 81 | - result.vultr_startup_script.script == '{{ vultr_startup_script }}' 82 | 83 | - name: test update startup script 84 | vultr_startup_script: 85 | name: "{{ vultr_startup_script_name }}" 86 | script: "{{ vultr_startup_script2 }}" 87 | register: result 88 | - name: verify test update startup script 89 | assert: 90 | that: 91 | - result is changed 92 | - result.vultr_startup_script.name == '{{ vultr_startup_script_name }}' 93 | - result.vultr_startup_script.script == '{{ vultr_startup_script2 }}' 94 | 95 | - name: test update startup script idempotence 96 | vultr_startup_script: 97 | name: "{{ vultr_startup_script_name }}" 98 | script: "{{ vultr_startup_script2 }}" 99 | register: result 100 | - name: verify test update startup script idempotence 101 | assert: 102 | that: 103 | - result is not changed 104 | - result.vultr_startup_script.name == '{{ vultr_startup_script_name }}' 105 | - result.vultr_startup_script.script == '{{ vultr_startup_script2 }}' 106 | 107 | - name: test absent startup script in check mode 108 | vultr_startup_script: 109 | name: "{{ vultr_startup_script_name }}" 110 | state: absent 111 | register: result 112 | check_mode: yes 113 | - name: verify test absent startup script in check mode 114 | assert: 115 | that: 116 | - result is changed 117 | - result.vultr_startup_script.name == '{{ vultr_startup_script_name }}' 118 | - result.vultr_startup_script.script == '{{ vultr_startup_script2 }}' 119 | 120 | - name: test absent startup script 121 | vultr_startup_script: 122 | name: "{{ vultr_startup_script_name }}" 123 | state: absent 124 | register: result 125 | - name: verify test absent startup script 126 | assert: 127 | that: 128 | - result is changed 129 | - result.vultr_startup_script.name == '{{ vultr_startup_script_name }}' 130 | - result.vultr_startup_script.script == '{{ vultr_startup_script2 }}' 131 | 132 | - name: test absent startup script idempotence 133 | vultr_startup_script: 134 | name: "{{ vultr_startup_script_name }}" 135 | state: absent 136 | register: result 137 | - name: verify test absent startup script idempotence 138 | assert: 139 | that: 140 | - result is not changed 141 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_startup_script_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_startup_script_info/defaults/main.yml: -------------------------------------------------------------------------------- 1 | vultr_resource_prefix: "vultr_test_prefix" 2 | startup_script_name: "{{ vultr_resource_prefix }}_script" 3 | startup_script_type: boot 4 | startup_script_content: "#!/bin/bash\necho Hello World > /root/hello" 5 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_startup_script_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | - name: test gather vultr startup script info - empty resources 5 | vultr_startup_script_info: 6 | 7 | - name: Create the script 8 | vultr_startup_script: 9 | name: '{{ startup_script_name }}' 10 | script_type: '{{ startup_script_type }}' 11 | script: '{{ startup_script_content }}' 12 | 13 | - name: test gather vultr startup script info in check mode 14 | vultr_startup_script_info: 15 | check_mode: yes 16 | register: result 17 | 18 | - name: verify test gather vultr startup script info in check mode 19 | assert: 20 | that: 21 | - result.vultr_startup_script_info|selectattr('name','equalto','{{ startup_script_name }}') | list | count == 1 22 | 23 | - name: test gather vultr startup script info 24 | vultr_startup_script_info: 25 | register: result 26 | 27 | - name: verify test gather vultr startup script info 28 | assert: 29 | that: 30 | - result.vultr_startup_script_info|selectattr('name','equalto','{{ startup_script_name }}') | list | count == 1 31 | 32 | - name: Delete the script 33 | vultr_startup_script: 34 | name: '{{ startup_script_name }}' 35 | state: absent 36 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_user/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_user/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, René Moser 2 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 3 | --- 4 | vultr_resource_prefix: "vultr-test-prefix" 5 | vultr_user_name: "{{ vultr_resource_prefix }}_user" 6 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_user/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Copyright (c) 2018, René Moser 3 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 4 | - name: setup 5 | vultr_user: 6 | name: "{{ vultr_user_name }}" 7 | state: absent 8 | register: result 9 | - name: verify setup 10 | assert: 11 | that: 12 | - result is success 13 | 14 | - name: test fail if missing name 15 | vultr_user: 16 | register: result 17 | ignore_errors: yes 18 | - name: verify test fail if missing name 19 | assert: 20 | that: 21 | - result is failed 22 | - 'result.msg == "missing required arguments: name"' 23 | 24 | - name: test fail if missing params for state=present 25 | vultr_user: 26 | name: "{{ vultr_user_name }}" 27 | register: result 28 | ignore_errors: yes 29 | - name: verify fail if missing params for state=present 30 | assert: 31 | that: 32 | - result is failed 33 | - 'result.msg.startswith("state is present but all of the following are missing")' 34 | 35 | - name: test fail param not in choices 36 | vultr_user: 37 | name: "{{ vultr_user_name }}" 38 | email: john.doe@example.com 39 | password: s3cr3t 40 | acls: 41 | - bad 42 | - dns 43 | - manage_users 44 | register: result 45 | ignore_errors: yes 46 | - name: verify test fail if missing name 47 | assert: 48 | that: 49 | - result is failed 50 | - 'result.msg.startswith("value of acls must be one or more of")' 51 | 52 | - name: test create user in check mode 53 | vultr_user: 54 | name: "{{ vultr_user_name }}" 55 | email: john.doe@example.com 56 | password: s3cr3t 57 | acls: 58 | - upgrade 59 | - dns 60 | - manage_users 61 | register: result 62 | check_mode: yes 63 | - name: verify test create user in check mode 64 | assert: 65 | that: 66 | - result is changed 67 | 68 | - name: test create user 69 | vultr_user: 70 | name: "{{ vultr_user_name }}" 71 | email: john.doe@example.com 72 | password: s3cr3t 73 | acls: 74 | - upgrade 75 | - dns 76 | - manage_users 77 | register: result 78 | - name: verify test create user 79 | assert: 80 | that: 81 | - result is changed 82 | - result.vultr_user.name == '{{ vultr_user_name }}' 83 | - result.vultr_user.email == 'john.doe@example.com' 84 | - result.vultr_user.api_enabled == true 85 | - "'upgrade' in result.vultr_user.acls" 86 | - "'manage_users' in result.vultr_user.acls" 87 | - "'dns' in result.vultr_user.acls" 88 | - result.vultr_user.api_key is defined 89 | 90 | - name: test create user idempotence 91 | vultr_user: 92 | name: "{{ vultr_user_name }}" 93 | email: john.doe@example.com 94 | password: s3cr3t 95 | acls: 96 | - upgrade 97 | - dns 98 | - manage_users 99 | register: result 100 | - name: verify test create user idempotence 101 | assert: 102 | that: 103 | - result is not changed 104 | - result.vultr_user.name == '{{ vultr_user_name }}' 105 | - result.vultr_user.email == 'john.doe@example.com' 106 | - result.vultr_user.api_enabled == true 107 | - "'upgrade' in result.vultr_user.acls" 108 | - "'manage_users' in result.vultr_user.acls" 109 | - "'dns' in result.vultr_user.acls" 110 | - result.vultr_user.api_key is not defined 111 | 112 | - name: test update user in check mode 113 | vultr_user: 114 | name: "{{ vultr_user_name }}" 115 | email: jimmy@example.com 116 | password: s3cr3t 117 | api_enabled: false 118 | acls: 119 | - manage_users 120 | - upgrade 121 | - support 122 | register: result 123 | check_mode: yes 124 | - name: verify test update user in check mode 125 | assert: 126 | that: 127 | - result is changed 128 | - result.vultr_user.name == '{{ vultr_user_name }}' 129 | - result.vultr_user.email == 'john.doe@example.com' 130 | - "'upgrade' in result.vultr_user.acls" 131 | - "'manage_users' in result.vultr_user.acls" 132 | - "'dns' in result.vultr_user.acls" 133 | - result.vultr_user.api_enabled == true 134 | - result.vultr_user.api_key is not defined 135 | 136 | - name: test update user 137 | vultr_user: 138 | name: "{{ vultr_user_name }}" 139 | email: jimmy@example.com 140 | password: s3cr3t 141 | api_enabled: false 142 | acls: 143 | - manage_users 144 | - upgrade 145 | - support 146 | register: result 147 | - name: verify test update user 148 | assert: 149 | that: 150 | - result is changed 151 | - result.vultr_user.name == '{{ vultr_user_name }}' 152 | - result.vultr_user.email == 'jimmy@example.com' 153 | - "'upgrade' in result.vultr_user.acls" 154 | - "'manage_users' in result.vultr_user.acls" 155 | - "'support' in result.vultr_user.acls" 156 | - result.vultr_user.api_enabled == false 157 | - result.vultr_user.api_key is not defined 158 | 159 | - name: test update user idempotence 160 | vultr_user: 161 | name: "{{ vultr_user_name }}" 162 | email: jimmy@example.com 163 | password: s3cr3t 164 | api_enabled: false 165 | acls: 166 | - manage_users 167 | - upgrade 168 | - support 169 | register: result 170 | - name: verify test update user idempotence 171 | assert: 172 | that: 173 | - result is not changed 174 | - result.vultr_user.name == '{{ vultr_user_name }}' 175 | - result.vultr_user.email == 'jimmy@example.com' 176 | - "'upgrade' in result.vultr_user.acls" 177 | - "'manage_users' in result.vultr_user.acls" 178 | - "'support' in result.vultr_user.acls" 179 | - result.vultr_user.api_enabled == false 180 | - result.vultr_user.api_key is not defined 181 | 182 | - name: test absent user in check mode 183 | vultr_user: 184 | name: "{{ vultr_user_name }}" 185 | state: absent 186 | register: result 187 | check_mode: yes 188 | - name: verify test absent user in check mode 189 | assert: 190 | that: 191 | - result is changed 192 | - result.vultr_user.name == '{{ vultr_user_name }}' 193 | - result.vultr_user.email == 'jimmy@example.com' 194 | - "'upgrade' in result.vultr_user.acls" 195 | - "'manage_users' in result.vultr_user.acls" 196 | - "'support' in result.vultr_user.acls" 197 | - result.vultr_user.api_enabled == false 198 | - result.vultr_user.api_key is not defined 199 | 200 | - name: test absent user 201 | vultr_user: 202 | name: "{{ vultr_user_name }}" 203 | state: absent 204 | register: result 205 | - name: verify test absent user 206 | assert: 207 | that: 208 | - result is changed 209 | - result.vultr_user.name == '{{ vultr_user_name }}' 210 | - result.vultr_user.email == 'jimmy@example.com' 211 | - "'upgrade' in result.vultr_user.acls" 212 | - "'manage_users' in result.vultr_user.acls" 213 | - "'support' in result.vultr_user.acls" 214 | - result.vultr_user.api_enabled == false 215 | - result.vultr_user.api_key is not defined 216 | 217 | - name: test absent user idempotence 218 | vultr_user: 219 | name: "{{ vultr_user_name }}" 220 | state: absent 221 | register: result 222 | - name: verify test absent user idempotence 223 | assert: 224 | that: 225 | - result is not changed 226 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_user_info/aliases: -------------------------------------------------------------------------------- 1 | cloud/vultr 2 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_user_info/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | vultr_resource_prefix: "vultr-test-prefix" 3 | user_name: "{{ vultr_resource_prefix }}_user" 4 | user_email: mytestuser-{{ vultr_resource_prefix }}@example.com 5 | user_password: "{{ vultr_resource_prefix }}aP4ssw0rd!" 6 | user_acls: 7 | - upgrade 8 | - dns 9 | - manage_users 10 | - subscriptions 11 | -------------------------------------------------------------------------------- /tests/integration/targets/vultr_user_info/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Yanis Guenane 2 | # Copyright (c) 2019, René Moser 3 | # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 4 | --- 5 | - name: Create the user 6 | vultr_user: 7 | name: '{{ user_name }}' 8 | email: '{{ user_email }}' 9 | password: '{{ user_password }}' 10 | acls: '{{ user_acls }}' 11 | 12 | - name: test get vultr user info in check mode 13 | vultr_user_info: 14 | register: result 15 | check_mode: yes 16 | 17 | - name: verify test get vultr user info in check mode 18 | assert: 19 | that: 20 | - result.vultr_user_info|selectattr('name','equalto','{{ user_name }}') | list | count == 1 21 | 22 | - name: test get vultr user info 23 | vultr_user_info: 24 | register: result 25 | 26 | - name: verify test get vultr user info 27 | assert: 28 | that: 29 | - result.vultr_user_info|selectattr('name','equalto','{{ user_name }}') | list | count == 1 30 | 31 | - name: Delete the user 32 | vultr_user: 33 | name: '{{ user_name }}' 34 | state: absent 35 | -------------------------------------------------------------------------------- /tests/sanity/ignore-2.10.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ngine-io/ansible-collection-vultr/81d1926818d1a9e0d5e485d73797c0f951395581/tests/sanity/ignore-2.10.txt --------------------------------------------------------------------------------