Fixup volume creation functionality
This commit is contained in:
parent
5fd3f5ca94
commit
1423840fba
@ -14,7 +14,8 @@ new major version of Molecule. If you use the `volumes:` key in your
|
||||
`molecule.yml` then this change will break your configuration. Please see the
|
||||
section on "Volume Handling" in the README.md on how to upgrade successfully.
|
||||
You will now need to install Ansible yourself as Molecule does not do it for
|
||||
you.
|
||||
you. If there are any other breaking changes, please report them on the issue
|
||||
tracker so that we can mention them here.
|
||||
|
||||
- Support Python 3.9.
|
||||
- Support Molecule 3.2.1
|
||||
|
11
README.md
11
README.md
@ -82,11 +82,16 @@ after use.
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
name: "molecule-hetznercloud-volume-${INSTANCE_UUID}"
|
||||
size: 11
|
||||
create: true
|
||||
- name: "molecule-hetznercloud-volume-1-${INSTANCE_UUID}"
|
||||
- name: "molecule-hetznercloud-volume-2-${INSTANCE_UUID}"
|
||||
```
|
||||
|
||||
Supported keys are:
|
||||
|
||||
- **name** (required): name of volume
|
||||
- **size** (optional, default: `10GB`): size of volume
|
||||
- **location** (optional, default: `omitted`): path for volume
|
||||
|
||||
## Only use `molecule.yml` for configuration
|
||||
|
||||
It is being worked on that it is possible to remove all the files except the
|
||||
|
@ -8,9 +8,8 @@ platforms:
|
||||
server_type: cx11
|
||||
image: debian-10
|
||||
volumes:
|
||||
name: "molecule-hetznercloud-volume-${INSTANCE_UUID}"
|
||||
size: 11
|
||||
create: true
|
||||
- name: "molecule-hetznercloud-volume-1-${INSTANCE_UUID}"
|
||||
# - name: "molecule-hetznercloud-volume-2-${INSTANCE_UUID}"
|
||||
provisioner:
|
||||
name: ansible
|
||||
verifier:
|
||||
|
@ -53,16 +53,13 @@
|
||||
|
||||
- name: Create volume(s)
|
||||
hcloud_volume:
|
||||
name: "{{ item.volumes.name | default(item.name) }}"
|
||||
server: "{{ item.name }}"
|
||||
location: "{{ item.volumes.location | default(omit) }}"
|
||||
size: "{{ item.volumes.size | default(10) }}"
|
||||
name: "{{ item.1.name | default(item.0.name) }}"
|
||||
server: "{{ item.0.name }}"
|
||||
location: "{{ item.1.location | default(omit) }}"
|
||||
size: "{{ item.1.size | default(10) }}"
|
||||
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
|
||||
state: "present"
|
||||
with_items: "{{ molecule_yml.platforms }}"
|
||||
when:
|
||||
- item.volumes is defined
|
||||
- item.volumes.create | default(False) | bool
|
||||
loop: "{{ molecule_yml.platforms|subelements('volumes', skip_missing=True)}}"
|
||||
register: volumes
|
||||
async: 7200
|
||||
poll: 0
|
||||
@ -73,19 +70,23 @@
|
||||
register: hetzner_volumes
|
||||
until: hetzner_volumes.finished
|
||||
retries: 300
|
||||
when: volumes.changed
|
||||
when:
|
||||
- volumes is defined
|
||||
- volumes.changed
|
||||
with_items: "{{ volumes.results }}"
|
||||
|
||||
- name: Populate instance config dict
|
||||
set_fact:
|
||||
instance_conf_dict: {
|
||||
'instance': "{{ item.hcloud_server.name }}",
|
||||
'ssh_key_name': "{{ ssh_key_name }}",
|
||||
'address': "{{ item.hcloud_server.ipv4_address }}",
|
||||
'user': "{{ ssh_user }}",
|
||||
'port': "{{ ssh_port }}",
|
||||
'identity_file': "{{ ssh_path }}",
|
||||
'volumes': "{{ item.item.item.volumes | default({}) }}", }
|
||||
instance_conf_dict:
|
||||
{
|
||||
"instance": "{{ item.hcloud_server.name }}",
|
||||
"ssh_key_name": "{{ ssh_key_name }}",
|
||||
"address": "{{ item.hcloud_server.ipv4_address }}",
|
||||
"user": "{{ ssh_user }}",
|
||||
"port": "{{ ssh_port }}",
|
||||
"identity_file": "{{ ssh_path }}",
|
||||
"volumes": "{{ item.item.item.volumes | default({}) }}",
|
||||
}
|
||||
with_items: "{{ hetzner_jobs.results }}"
|
||||
register: instance_config_dict
|
||||
when: server.changed | bool
|
||||
|
@ -41,12 +41,9 @@
|
||||
name: "{{ item.volumes.name | default(item.instance) }}"
|
||||
server: "{{ item.instance }}"
|
||||
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
|
||||
state: "absent"
|
||||
state: absent
|
||||
register: volumes
|
||||
with_items: "{{ instance_conf }}"
|
||||
when:
|
||||
- item.volumes is defined
|
||||
- item.volumes.create | default(False) | bool
|
||||
async: 7200
|
||||
poll: 0
|
||||
|
||||
@ -66,7 +63,7 @@
|
||||
state: absent
|
||||
when:
|
||||
- not skip_instances
|
||||
- instance_conf | length # must contain at least one instance
|
||||
- instance_conf | length # must contain at least one instance
|
||||
|
||||
- name: Populate instance config
|
||||
set_fact:
|
||||
|
@ -10,7 +10,7 @@ def _model_platform_hetznercloud_section_data():
|
||||
{
|
||||
"name": "instance",
|
||||
"server_type": "",
|
||||
"volumes": {},
|
||||
"volumes": [],
|
||||
"image": "",
|
||||
"location": "",
|
||||
"datacenter": "",
|
||||
@ -57,7 +57,7 @@ def test_platforms_hetznercloud_has_errors(_config):
|
||||
{
|
||||
"name": ["must be of string type"],
|
||||
"server_type": ["must be of string type"],
|
||||
"volumes": ["must be of dict type"],
|
||||
"volumes": ["must be of list type"],
|
||||
"image": ["must be of string type"],
|
||||
"location": ["must be of string type"],
|
||||
"datacenter": ["must be of string type"],
|
||||
|
Loading…
Reference in New Issue
Block a user