Skip to content

Commit dc36bd6

Browse files
committed
fix drone config
1 parent e9b504a commit dc36bd6

File tree

9 files changed

+373
-1
lines changed

9 files changed

+373
-1
lines changed

.drone.jsonnet

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ local PipelineRelease = {
112112
'testing-centos7',
113113
'testing-rocky8',
114114
'testing-opensuse15',
115+
'testing-debian11',
115116
],
116117
trigger: {
117118
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
@@ -207,6 +208,7 @@ local PipelineNotification = {
207208
PipelineTesting(scenario='centos7'),
208209
PipelineTesting(scenario='rocky8'),
209210
PipelineTesting(scenario='opensuse15'),
211+
PipelineTesting(scenario='debian11'),
210212
PipelineRelease,
211213
PipelineDocumentation,
212214
PipelineNotification,

.drone.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,40 @@ trigger:
170170
depends_on:
171171
- linting
172172

173+
---
174+
kind: pipeline
175+
name: testing-debian11
176+
177+
platform:
178+
os: linux
179+
arch: amd64
180+
181+
concurrency:
182+
limit: 1
183+
184+
workspace:
185+
base: /drone/src
186+
path: redis
187+
188+
steps:
189+
- name: molecule
190+
image: thegeeklab/molecule:3
191+
commands:
192+
- molecule test -s debian11
193+
environment:
194+
HCLOUD_TOKEN:
195+
from_secret: hcloud_token
196+
PY_COLORS: 1
197+
198+
trigger:
199+
ref:
200+
- refs/heads/main
201+
- refs/tags/**
202+
- refs/pull/**
203+
204+
depends_on:
205+
- linting
206+
173207
---
174208
kind: pipeline
175209
name: release
@@ -209,6 +243,7 @@ depends_on:
209243
- testing-centos7
210244
- testing-rocky8
211245
- testing-opensuse15
246+
- testing-debian11
212247

213248
---
214249
kind: pipeline
@@ -293,6 +328,6 @@ depends_on:
293328

294329
---
295330
kind: signature
296-
hmac: 8ece82098addbb6ded7dcf88cb75e03dd0d028840224bb4b5168b3be35f8e9dc
331+
hmac: 34bdef932a311ec6826159aa17bd1e21fb0327281d7e5a17c8b5093e6a84df56
297332

298333
...

molecule/debian11/converge.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
- name: Converge
3+
hosts: all
4+
vars:
5+
redis_apt_cache_update: True
6+
7+
roles:
8+
- role: redis

molecule/debian11/create.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
- name: Create
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
no_log: "{{ molecule_no_log }}"
7+
vars:
8+
ssh_port: 22
9+
ssh_user: root
10+
ssh_path: "{{ lookup('env', 'MOLECULE_EPHEMERAL_DIRECTORY') }}/ssh_key"
11+
tasks:
12+
- name: Create SSH key
13+
user:
14+
name: "{{ lookup('env', 'USER') }}"
15+
generate_ssh_key: true
16+
ssh_key_file: "{{ ssh_path }}"
17+
force: true
18+
register: generated_ssh_key
19+
20+
- name: Register the SSH key name
21+
set_fact:
22+
ssh_key_name: "molecule-generated-{{ 12345 | random | to_uuid }}"
23+
24+
- name: Register SSH key for test instance(s)
25+
hcloud_ssh_key:
26+
name: "{{ ssh_key_name }}"
27+
public_key: "{{ generated_ssh_key.ssh_public_key }}"
28+
state: present
29+
30+
- name: Create molecule instance(s)
31+
hcloud_server:
32+
name: "{{ item.name }}"
33+
server_type: "{{ item.server_type }}"
34+
ssh_keys:
35+
- "{{ ssh_key_name }}"
36+
image: "{{ item.image }}"
37+
location: "{{ item.location | default(omit) }}"
38+
datacenter: "{{ item.datacenter | default(omit) }}"
39+
user_data: "{{ item.user_data | default(omit) }}"
40+
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
41+
state: present
42+
register: server
43+
loop: "{{ molecule_yml.platforms }}"
44+
async: 7200
45+
poll: 0
46+
47+
- name: Wait for instance(s) creation to complete
48+
async_status:
49+
jid: "{{ item.ansible_job_id | string }}"
50+
register: hetzner_jobs
51+
until: hetzner_jobs.finished
52+
retries: 300
53+
loop: "{{ server.results }}"
54+
55+
- name: Create volume(s)
56+
hcloud_volume:
57+
name: "{{ item.name }}"
58+
server: "{{ item.name }}"
59+
location: "{{ item.location | default(omit) }}"
60+
size: "{{ item.volume_size | default(10) }}"
61+
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
62+
state: "present"
63+
loop: "{{ molecule_yml.platforms }}"
64+
when: item.volume | default(False) | bool
65+
register: volumes
66+
async: 7200
67+
poll: 0
68+
69+
- name: Wait for volume(s) creation to complete
70+
async_status:
71+
jid: "{{ item.ansible_job_id | string }}"
72+
register: hetzner_volumes
73+
until: hetzner_volumes.finished
74+
retries: 300
75+
when: volumes.changed
76+
loop: "{{ volumes.results }}"
77+
78+
# Mandatory configuration for Molecule to function.
79+
80+
- name: Populate instance config dict
81+
set_fact:
82+
instance_conf_dict:
83+
{
84+
"instance": "{{ item.hcloud_server.name }}",
85+
"ssh_key_name": "{{ ssh_key_name }}",
86+
"address": "{{ item.hcloud_server.ipv4_address }}",
87+
"user": "{{ ssh_user }}",
88+
"port": "{{ ssh_port }}",
89+
"identity_file": "{{ ssh_path }}",
90+
"volume": "{{ item.item.item.volume | default(False) | bool }}",
91+
"from_snapshot": "{{ item.item.item.from_snapshot | default(False) | bool }}",
92+
}
93+
loop: "{{ hetzner_jobs.results }}"
94+
register: instance_config_dict
95+
when: server.changed | bool
96+
97+
- name: Convert instance config dict to a list
98+
set_fact:
99+
instance_conf: "{{ instance_config_dict.results | map(attribute='ansible_facts.instance_conf_dict') | list }}"
100+
when: server.changed | bool
101+
102+
- name: Dump instance config
103+
copy:
104+
content: |
105+
# Molecule managed
106+
107+
{{ instance_conf | to_nice_yaml(indent=2) }}
108+
dest: "{{ molecule_instance_config }}"
109+
when: server.changed | bool
110+
111+
- name: Wait for SSH
112+
wait_for:
113+
port: "{{ ssh_port }}"
114+
host: "{{ item.address }}"
115+
search_regex: SSH
116+
delay: 10
117+
loop: "{{ lookup('file', molecule_instance_config) | from_yaml }}"
118+
119+
- name: Wait for VM to settle down
120+
pause:
121+
seconds: 30

molecule/debian11/destroy.yml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
- name: Destroy
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
no_log: "{{ molecule_no_log }}"
7+
tasks:
8+
- name: Check existing instance config file
9+
stat:
10+
path: "{{ molecule_instance_config }}"
11+
register: cfg
12+
13+
- name: Populate the instance config
14+
set_fact:
15+
instance_conf: "{{ (lookup('file', molecule_instance_config) | from_yaml) if cfg.stat.exists else [] }}"
16+
17+
- name: Destroy molecule instance(s)
18+
hcloud_server:
19+
name: "{{ item.instance }}"
20+
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
21+
state: absent
22+
register: server
23+
loop: "{{ instance_conf }}"
24+
async: 7200
25+
poll: 0
26+
27+
- name: Wait for instance(s) deletion to complete
28+
async_status:
29+
jid: "{{ item.ansible_job_id | string }}"
30+
register: hetzner_jobs
31+
until: hetzner_jobs.finished
32+
retries: 300
33+
loop: "{{ server.results }}"
34+
35+
- pause:
36+
seconds: 5
37+
38+
- name: Destroy volume(s)
39+
hcloud_volume:
40+
name: "{{ item.instance }}"
41+
server: "{{ item.instance }}"
42+
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
43+
state: "absent"
44+
register: volumes
45+
loop: "{{ instance_conf }}"
46+
when: item.volume | default(False) | bool
47+
async: 7200
48+
poll: 0
49+
50+
- name: Wait for volume(s) deletion to complete
51+
async_status:
52+
jid: "{{ item.ansible_job_id | string }}"
53+
register: hetzner_volumes
54+
until: hetzner_volumes.finished
55+
retries: 300
56+
when: volumes.changed
57+
loop: "{{ volumes.results }}"
58+
59+
- name: Remove registered SSH key
60+
hcloud_ssh_key:
61+
name: "{{ instance_conf[0].ssh_key_name }}"
62+
state: absent
63+
when: (instance_conf | default([])) | length > 0
64+
65+
# Mandatory configuration for Molecule to function.
66+
67+
- name: Populate instance config
68+
set_fact:
69+
instance_conf: {}
70+
71+
- name: Dump instance config
72+
copy:
73+
content: |
74+
# Molecule managed
75+
76+
{{ instance_conf | to_nice_yaml(indent=2) }}
77+
dest: "{{ molecule_instance_config }}"
78+
when: server.changed | bool
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
- block:
3+
- name: Restart in rescue mode
4+
hcloud_server:
5+
name: "{{ item.instance }}"
6+
ssh_keys:
7+
- "{{ item.ssh_key_name }}"
8+
api_token: "{{ lookup('env', 'HCLOUD_TOKEN') }}"
9+
rescue_mode: linux64
10+
state: restarted
11+
async: 7200
12+
poll: 0
13+
14+
- name: Wait for SSH
15+
wait_for:
16+
port: "{{ item.port }}"
17+
host: "{{ item.address }}"
18+
search_regex: SSH
19+
delay: 10
20+
delegate_to: localhost
21+
22+
- name: Mount root user volume
23+
mount:
24+
path: /mnt/root
25+
src: /dev/sda2
26+
fstype: btrfs
27+
opts: subvol=@/root
28+
fstab: /tmp/fstab
29+
state: mounted
30+
31+
- name: Add ssh public key
32+
authorized_key:
33+
user: root
34+
path: /mnt/root/.ssh/authorized_keys
35+
key: "{{ lookup('file', item.identity_file + '.pub') }}"
36+
state: present
37+
38+
- name: Restart server
39+
reboot:
40+
41+
- name: Wait for SSH
42+
wait_for:
43+
port: "{{ item.port }}"
44+
host: "{{ item.address }}"
45+
search_regex: SSH
46+
delay: 10
47+
delegate_to: localhost

molecule/debian11/molecule.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
options:
5+
role-file: molecule/requirements.yml
6+
env:
7+
ANSIBLE_GALAXY_DISPLAY_PROGRESS: "false"
8+
driver:
9+
name: delegated
10+
platforms:
11+
- name: debian-11-redis
12+
server_type: cx11
13+
image: debian-11
14+
lint: |
15+
/usr/local/bin/flake8
16+
provisioner:
17+
name: ansible
18+
env:
19+
ANSIBLE_FILTER_PLUGINS: ${ANSIBLE_FILTER_PLUGINS:-./plugins/filter}
20+
ANSIBLE_LIBRARY: ${ANSIBLE_LIBRARY:-./library}
21+
log: false
22+
verifier:
23+
name: testinfra

molecule/debian11/prepare.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
- name: Prepare
3+
hosts: all
4+
gather_facts: false
5+
tasks:
6+
- name: Check existing instance config file
7+
stat:
8+
path: "{{ molecule_instance_config }}"
9+
register: cfg
10+
delegate_to: localhost
11+
run_once: true
12+
13+
- name: Populate the instance config
14+
no_log: "{{ molecule_no_log }}"
15+
set_fact:
16+
instance_conf: "{{ (lookup('file', molecule_instance_config) | from_yaml) if cfg.stat.exists else [] }}"
17+
delegate_to: localhost
18+
run_once: true
19+
20+
- name: Prepare instance(s) from snapshot
21+
no_log: "{{ molecule_no_log }}"
22+
include_tasks: from_snapshot.yml
23+
loop: "{{ instance_conf }}"
24+
when:
25+
- inventory_hostname == item.instance
26+
- item.from_snapshot | bool
27+
28+
- name: Bootstrap python for Ansible
29+
raw: |
30+
command -v python3 python || (
31+
(test -e /usr/bin/dnf && sudo dnf install -y python3) ||
32+
(test -e /usr/bin/apt && (apt -y update && apt install -y python-minimal)) ||
33+
(test -e /usr/bin/yum && sudo yum -y -qq install python3) ||
34+
echo "Warning: Python not boostrapped due to unknown platform."
35+
)
36+
become: true
37+
changed_when: false

0 commit comments

Comments
 (0)