-
Notifications
You must be signed in to change notification settings - Fork 666
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
27 changed files
with
1,034 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
molecule/cookiecutter/scenario/driver/hetznercloud/cookiecutter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"molecule_directory": "molecule", | ||
"role_name": "OVERRIDEN", | ||
"scenario_name": "OVERRIDEN" | ||
} |
23 changes: 23 additions & 0 deletions
23
.../{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/INSTALL.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
*************************************** | ||
Hetzner Cloud driver installation guide | ||
*************************************** | ||
|
||
Requirements | ||
============ | ||
|
||
* Ansible 2.8+ | ||
* ``HCLOUD_TOKEN`` exposed in your environment | ||
|
||
Install | ||
======= | ||
|
||
Please refer to the `Virtual environment`_ documentation for installation best | ||
practices. If not using a virtual environment, please consider passing the | ||
widely recommended `'--user' flag`_ when invoking ``pip``. | ||
|
||
.. _Virtual environment: https://virtualenv.pypa.io/en/latest/ | ||
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site | ||
|
||
.. code-block:: bash | ||
$ pip install 'molecule[hetznercloud]' |
68 changes: 68 additions & 0 deletions
68
...etznercloud/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/create.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
--- | ||
{% raw -%} | ||
- name: Create | ||
hosts: localhost | ||
connection: local | ||
gather_facts: false | ||
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}" | ||
vars: | ||
ssh_port: 22 | ||
ssh_user: root | ||
tasks: | ||
- name: Create molecule instance(s) | ||
hcloud_server: | ||
name: "{{ item.name }}" | ||
server_type: "{{ item.server_type }}" | ||
ssh_keys: "{{ item.ssh_keys }}" | ||
volumes: "{{ item.volumes | default(omit) }}" | ||
image: "{{ item.image }}" | ||
location: "{{ item.location | default(omit) }}" | ||
datacenter: "{{ item.datacenter | default(omit) }}" | ||
user_data: "{{ item.user_data | default(omit) }}" | ||
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}" | ||
state: present | ||
register: server | ||
with_items: "{{ molecule_yml.platforms }}" | ||
async: 7200 | ||
poll: 0 | ||
|
||
- name: Wait for instance(s) creation to complete | ||
async_status: | ||
jid: "{{ item.ansible_job_id }}" | ||
register: hetzner_jobs | ||
until: hetzner_jobs.finished | ||
retries: 300 | ||
with_items: "{{ server.results }}" | ||
|
||
# Mandatory configuration for Molecule to function. | ||
|
||
- name: Populate instance config dict | ||
set_fact: | ||
instance_conf_dict: { | ||
'instance': "{{ item.hcloud_server.name }}", | ||
'user': "{{ ssh_user }}", | ||
'port': "{{ ssh_port }}", | ||
'address': "{{ item.hcloud_server.ipv4_address }}", } | ||
with_items: "{{ hetzner_jobs.results }}" | ||
register: instance_config_dict | ||
when: server.changed | bool | ||
|
||
- name: Convert instance config dict to a list | ||
set_fact: | ||
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}" | ||
when: server.changed | bool | ||
|
||
- name: Dump instance config | ||
copy: | ||
content: "{{ instance_conf | to_json | from_json | molecule_to_yaml | molecule_header }}" | ||
dest: "{{ molecule_instance_config }}" | ||
when: server.changed | bool | ||
|
||
- name: Wait for SSH | ||
wait_for: | ||
port: "{{ ssh_port }}" | ||
host: "{{ item.address }}" | ||
search_regex: SSH | ||
delay: 10 | ||
with_items: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}" | ||
{%- endraw %} |
50 changes: 50 additions & 0 deletions
50
...tznercloud/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/destroy.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
{% raw -%} | ||
- name: Destroy | ||
hosts: localhost | ||
connection: local | ||
gather_facts: false | ||
no_log: "{{ not (lookup('env', 'MOLECULE_DEBUG') | bool or molecule_yml.provisioner.log|default(false) | bool) }}" | ||
tasks: | ||
- block: | ||
- name: Populate instance config | ||
set_fact: | ||
instance_conf: "{{ lookup('file', molecule_instance_config) | molecule_from_yaml }}" | ||
skip_instances: false | ||
rescue: | ||
- name: Populate instance config when file missing | ||
set_fact: | ||
instance_conf: {} | ||
skip_instances: true | ||
|
||
- name: Destroy molecule instance(s) | ||
hcloud_server: | ||
name: "{{ item.instance }}" | ||
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}" | ||
state: absent | ||
register: server | ||
with_items: "{{ instance_conf }}" | ||
when: not skip_instances | ||
async: 7200 | ||
poll: 0 | ||
|
||
- name: Wait for instance(s) deletion to complete | ||
async_status: | ||
jid: "{{ item.ansible_job_id }}" | ||
register: hetzner_jobs | ||
until: hetzner_jobs.finished | ||
retries: 300 | ||
with_items: "{{ server.results }}" | ||
|
||
# Mandatory configuration for Molecule to function. | ||
|
||
- name: Populate instance config | ||
set_fact: | ||
instance_conf: {} | ||
|
||
- name: Dump instance config | ||
copy: | ||
content: "{{ instance_conf | molecule_to_yaml | molecule_header }}" | ||
dest: "{{ molecule_instance_config }}" | ||
when: server.changed | bool | ||
{%- endraw %} |
5 changes: 5 additions & 0 deletions
5
...znercloud/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/playbook.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
- name: Converge | ||
hosts: all | ||
roles: | ||
- role: {{ cookiecutter.role_name }} |
11 changes: 11 additions & 0 deletions
11
...tznercloud/{{cookiecutter.molecule_directory}}/{{cookiecutter.scenario_name}}/prepare.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
{% raw -%} | ||
- name: Prepare | ||
hosts: all | ||
gather_facts: false | ||
tasks: | ||
- name: Install python for Ansible | ||
raw: test -e /usr/bin/python || (apt -y update && apt install -y python-minimal python-zipstream) | ||
become: true | ||
changed_when: false | ||
{%- endraw %} |
Oops, something went wrong.