commit 25e84bb01295c41d81d9448efbd126627f927fa5 Author: Robert Kaussow Date: Sun May 17 20:19:07 2020 +0200 initial commit diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 0000000..aff5b65 --- /dev/null +++ b/.drone.jsonnet @@ -0,0 +1,117 @@ +local PipelineLinting = { + kind: 'pipeline', + name: 'linting', + platform: { + os: 'linux', + arch: 'amd64', + }, + steps: [ + { + name: 'ansible-later', + image: 'xoxys/ansible-later', + commands: [ + 'ansible-later', + ], + }, + ], + trigger: { + ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'], + }, +}; + +local PipelineDocumentation = { + kind: 'pipeline', + name: 'documentation', + platform: { + os: 'linux', + arch: 'amd64', + }, + steps: [ + { + name: 'generate', + image: 'xoxys/ansible-doctor', + environment: { + ANSIBLE_DOCTOR_LOG_LEVEL: 'INFO', + ANSIBLE_DOCTOR_FORCE_OVERWRITE: true, + ANSIBLE_DOCTOR_EXCLUDE_FILES: 'molecule/', + ANSIBLE_DOCTOR_TEMPLATE: 'hugo-book', + ANSIBLE_DOCTOR_ROLE_NAME: '${DRONE_REPO_NAME#*.}', + ANSIBLE_DOCTOR_OUTPUT_DIR: '_docs/', + }, + }, + { + name: 'publish', + image: 'plugins/gh-pages', + settings: { + remote_url: 'https://gitea.rknet.org/ansible/${DRONE_REPO_NAME}', + netrc_machine: 'gitea.rknet.org', + username: { from_secret: 'gitea_username' }, + password: { from_secret: 'gitea_token' }, + pages_directory: '_docs/', + target_branch: 'docs', + }, + when: { + ref: ['refs/heads/master'], + }, + }, + { + name: 'trigger', + image: 'plugins/downstream', + settings: { + server: 'https://drone.rknet.org', + token: { from_secret: 'drone_token' }, + fork: true, + repositories: [ + 'ansible/ansible-galaxy', + ], + }, + when: { + ref: ['refs/heads/master'], + }, + }, + ], + trigger: { + ref: ['refs/heads/master', 'refs/tags/**', 'refs/pull/**'], + }, + depends_on: [ + 'linting', + ], +}; + +local PipelineNotification = { + kind: 'pipeline', + name: 'notification', + platform: { + os: 'linux', + arch: 'amd64', + }, + clone: { + disable: true, + }, + steps: [ + { + name: 'matrix', + image: 'plugins/matrix', + settings: { + homeserver: { from_secret: 'matrix_homeserver' }, + roomid: { from_secret: 'matrix_roomid' }, + template: 'Status: **{{ build.status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}', + username: { from_secret: 'matrix_username' }, + password: { from_secret: 'matrix_password' }, + }, + }, + ], + depends_on: [ + 'documentation', + ], + trigger: { + status: ['success', 'failure'], + ref: ['refs/heads/master', 'refs/tags/**'], + }, +}; + +[ + PipelineLinting, + PipelineDocumentation, + PipelineNotification, +] diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..b9b00b3 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,117 @@ +--- +kind: pipeline +name: linting + +platform: + os: linux + arch: amd64 + +steps: +- name: ansible-later + image: xoxys/ansible-later + commands: + - ansible-later + +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +--- +kind: pipeline +name: documentation + +platform: + os: linux + arch: amd64 + +steps: +- name: generate + image: xoxys/ansible-doctor + environment: + ANSIBLE_DOCTOR_EXCLUDE_FILES: molecule/ + ANSIBLE_DOCTOR_FORCE_OVERWRITE: true + ANSIBLE_DOCTOR_LOG_LEVEL: INFO + ANSIBLE_DOCTOR_OUTPUT_DIR: _docs/ + ANSIBLE_DOCTOR_ROLE_NAME: ${DRONE_REPO_NAME#*.} + ANSIBLE_DOCTOR_TEMPLATE: hugo-book + +- name: publish + image: plugins/gh-pages + settings: + netrc_machine: gitea.rknet.org + pages_directory: _docs/ + password: + from_secret: gitea_token + remote_url: https://gitea.rknet.org/ansible/${DRONE_REPO_NAME} + target_branch: docs + username: + from_secret: gitea_username + when: + ref: + - refs/heads/master + +- name: trigger + image: plugins/downstream + settings: + fork: true + repositories: + - ansible/ansible-galaxy + server: https://drone.rknet.org + token: + from_secret: drone_token + when: + ref: + - refs/heads/master + +trigger: + ref: + - refs/heads/master + - refs/tags/** + - refs/pull/** + +depends_on: +- linting + +--- +kind: pipeline +name: notification + +platform: + os: linux + arch: amd64 + +clone: + disable: true + +steps: +- name: matrix + image: plugins/matrix + settings: + homeserver: + from_secret: matrix_homeserver + password: + from_secret: matrix_password + roomid: + from_secret: matrix_roomid + template: "Status: **{{ build.status }}**
Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}
Message: {{ build.message }}" + username: + from_secret: matrix_username + +trigger: + ref: + - refs/heads/master + - refs/tags/** + status: + - success + - failure + +depends_on: +- documentation + +--- +kind: signature +hmac: 53f7e3f985a0876e8abc38814d76ef9194a2d80d5e10126de2479ee358beba84 + +... diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..b41e1fc --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +ignore = D101, D102, D103, D105, D107, E402, W503 +max-line-length = 99 +inline-quotes = double +exclude = .git,.tox,__pycache__,build,dist,tests,*.pyc,*.egg-info,.cache,.eggs,env* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d97b7cd --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# ---> Ansible +*.retry +plugins +library + +# ---> Python +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + diff --git a/.later.yml b/.later.yml new file mode 100644 index 0000000..45911c9 --- /dev/null +++ b/.later.yml @@ -0,0 +1,18 @@ +--- +ansible: + custom_modules: + - iptables_raw + - openssl_pkcs12 + - proxmox_kvm2 + - ucr + - yum_versionlock + +rules: + exclude_files: + - molecule/ + - "LICENSE*" + - "**/*.md" + - "**/*.ini" + + exclude_filter: + - LINT0009 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..bb3e998 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Robert Kaussow + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..132a80f --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# xoxys.hcloud_server + +[![Build Status](https://img.shields.io/drone/build/ansible/xoxys.hcloud_server?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.hcloud_server) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](LICENSE) + +You can find the full documentation at [https://galaxy.geekdocs.de](https://galaxy.geekdocs.de/roles/cloud/hcloud_server/). + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. + +## Maintainers and Contributors + +[Robert Kaussow](https://gitea.rknet.org/xoxys) diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..463a1f3 --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,28 @@ +--- +hcloud_server: {} +# @var hcloud_server: example: > +# hcloud_server: +# name: my-server +# type: cx11 +# ssh_keys: [] +# image: +# location: "{{ hcloud_server_location }}" +# datacenter: "{{ hcloud_server_datacenter }}" +# api_token: "{{ hcloud_server_api_token | default(omit) }}" +# @end + +hcloud_server_volumes: [] +# @var hcloud_server_volumes:example: > +# hcloud_server_volumes: +# - name: my-volume +# size: 10 +# state: present +# @end + +hcloud_server_rdns: [] +# @var hcloud_server_rdns:example: > +# hcloud_server_rdns: +# - addr: 1.2.3.4 +# ptr: example.com +# state: present +# @end diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..f0a449e --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,21 @@ +# Standards: 0.1 +--- +galaxy_info: +# @meta author:value: [Robert Kaussow](https://gitea.rknet.org/xoxys) + author: "Robert Kaussow " +# @meta description: > +# [![Source Code](https://img.shields.io/badge/gitea-source%20code-blue?logo=gitea&logoColor=white)](https://gitea.rknet.org/ansible/xoxys.hcloud_server) +# [![Build Status](https://img.shields.io/drone/build/ansible/xoxys.hcloud_server?logo=drone&server=https%3A%2F%2Fdrone.rknet.org)](https://drone.rknet.org/ansible/xoxys.hcloud_server) +# [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?label=license)](LICENSE) +# +# Manage Hetzner Cloud server instances +# @end + description: Manage Hetzner Cloud server instances + license: MIT + min_ansible_version: 2.8 + platforms: + - name: EL + versions: + - 7 + galaxy_tags: +dependencies: [] diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..eed464c --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,5 @@ +--- +- include_tasks: setup.yml + when: + - hcloud_server is defined + - hcloud_server.name is defined diff --git a/tasks/setup.yml b/tasks/setup.yml new file mode 100644 index 0000000..73fc9c4 --- /dev/null +++ b/tasks/setup.yml @@ -0,0 +1,53 @@ +--- +- name: Provisioning VM '{{ hcloud_server.name }}' + hcloud_server: + name: "{{ hcloud_server.name }}" + server_type: "{{ hcloud_server.type | default('cx11') }}" + ssh_keys: "{{ hcloud_server.ssh_keys | default([]) }}" + image: "{{ hcloud_server.image | default('centos-7') }}" + location: "{{ hcloud_server.location | default('nbg1') }}" + api_token: "{{ hcloud_server.api_token | default(omit) }}" + state: present + register: __hcloud_server + async: 7200 + poll: 0 + delegate_to: localhost + +- name: Wait for instance creation to complete + async_status: + jid: "{{ server.ansible_job_id }}" + register: __hcloud_job + until: hcloud_job.finished + retries: 300 + delegate_to: localhost + +- name: Populate instance config + set_fact: + hcloud_instance: { + 'instance': "{{ __hcloud_job.hcloud_server.name }}", + 'ipv4': "{{ __hcloud_job.hcloud_server.ipv4_address }}", + 'ipv6': "{{ __hcloud_job.hcloud_server.ipv6 }}", + } + when: server.changed | bool + +- name: Create volumes + hcloud_volume: + name: "{{ item.name }}" + server: "{{ hcloud_server.name }}" + size: "{{ item.size | default(10) }}" + state: "{{ item.state | default('present') }}" + loop: "{{ hcloud_server_volumes }}" + loop_control: + label: "{{ item.name }}" + delegate_to: localhost + +- name: Create reverse DNS entries + hcloud_rdns: + server: "{{ hcloud_server.name }}" + ip_address: "{{ item.addr }}" + dns_ptr: "{{ item.ptr }}" + state: "{{ item.state | default('present') }}" + loop: "{{ hcloud_server_rdns }}" + loop_control: + label: "{{ item.name }}" + delegate_to: localhost