Skip to content

Commit 3a1a7a1

Browse files
Nomspleasetimothystewart6sleiner
authored
Fix LXC container implementations (#231)
* Need to become to reboot * Fix rc.local insertion of script * Fix syntax Add new line to lxc.yml * Remove need to set fact * Add reset for LXC container config * Fix syntax Its always the newlines.. * remove fact setting from reset task We should mirror the deployment task * Proxmox LXC reset functions * Handle if rc.local already has data * Dont compare literal * Cleanup Erroneous newline * Handle rc.local not present on a hybrid cluster * Update roles/reset/tasks/main.yml Co-authored-by: Simon Leiner <[email protected]> * Update roles/lxc/tasks/main.yml Co-authored-by: Simon Leiner <[email protected]> --------- Co-authored-by: Techno Tim <[email protected]> Co-authored-by: Simon Leiner <[email protected]>
1 parent 030eeb4 commit 3a1a7a1

File tree

8 files changed

+114
-6
lines changed

8 files changed

+114
-6
lines changed

reset.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@
1313
become: true
1414
reboot:
1515
reboot_timeout: 3600
16+
17+
- hosts: proxmox
18+
gather_facts: true
19+
become: yes
20+
remote_user: "{{ proxmox_lxc_ssh_user }}"
21+
roles:
22+
- role: reset_proxmox_lxc
23+
when: proxmox_lxc_configure

roles/lxc/handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
- name: reboot server
3+
become: true
34
reboot:

roles/lxc/tasks/main.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
---
2-
- name: configure rc.local for proxmox lxc containers
3-
copy:
4-
src: "{{ playbook_dir }}/scripts/rc.local"
5-
dest: "/etc/rc.local"
2+
- name: Check for rc.local file
3+
stat:
4+
path: /etc/rc.local
5+
register: rcfile
6+
7+
- name: Create rc.local if needed
8+
lineinfile:
9+
path: /etc/rc.local
10+
line: "#!/bin/sh -e"
11+
create: true
12+
insertbefore: BOF
613
mode: "u=rwx,g=rx,o=rx"
14+
when: not rcfile.stat.exists
15+
16+
- name: Write rc.local file
17+
blockinfile:
18+
path: /etc/rc.local
19+
content: "{{ lookup('template', 'templates/rc.local.j2') }}"
20+
state: present
721
notify: reboot server

roles/reset/tasks/main.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,31 @@
5454
file:
5555
path: /tmp/k3s
5656
state: absent
57+
58+
- name: Check if rc.local exists
59+
stat:
60+
path: /etc/rc.local
61+
register: rcfile
62+
63+
- name: Remove rc.local modifications for proxmox lxc containers
64+
become: true
65+
blockinfile:
66+
path: /etc/rc.local
67+
content: "{{ lookup('template', 'templates/rc.local.j2') }}"
68+
create: false
69+
state: absent
70+
when: proxmox_lxc_configure and rclocal.stat.exists
71+
72+
- name: Check rc.local for cleanup
73+
become: true
74+
slurp:
75+
src: /etc/rc.local
76+
register: rcslurp
77+
when: proxmox_lxc_configure and rclocal.stat.exists
78+
79+
- name: Cleanup rc.local if we only have a Shebang line
80+
become: true
81+
file:
82+
path: /etc/rc.local
83+
state: absent
84+
when: proxmox_lxc_configure and rclocal.stat.exists and ((rcslurp.content | b64decode).splitlines() | length) <= 1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
- name: reboot containers
3+
command:
4+
"pct reboot {{ item }}"
5+
loop: "{{ proxmox_lxc_filtered_ids }}"
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
- name: check for container files that exist on this host
3+
stat:
4+
path: "/etc/pve/lxc/{{ item }}.conf"
5+
loop: "{{ proxmox_lxc_ct_ids }}"
6+
register: stat_results
7+
8+
- name: filter out files that do not exist
9+
set_fact:
10+
proxmox_lxc_filtered_files:
11+
'{{ stat_results.results | rejectattr("stat.exists", "false") | map(attribute="stat.path") }}'
12+
13+
# used for the reboot handler
14+
- name: get container ids from filtered files
15+
set_fact:
16+
proxmox_lxc_filtered_ids:
17+
'{{ proxmox_lxc_filtered_files | map("split", "/") | map("last") | map("split", ".") | map("first") }}'
18+
19+
- name: Remove LXC apparmor profile
20+
lineinfile:
21+
dest: "{{ item }}"
22+
regexp: "^lxc.apparmor.profile"
23+
line: "lxc.apparmor.profile: unconfined"
24+
state: absent
25+
loop: "{{ proxmox_lxc_filtered_files }}"
26+
notify: reboot containers
27+
28+
- name: Remove lxc cgroups
29+
lineinfile:
30+
dest: "{{ item }}"
31+
regexp: "^lxc.cgroup.devices.allow"
32+
line: "lxc.cgroup.devices.allow: a"
33+
state: absent
34+
loop: "{{ proxmox_lxc_filtered_files }}"
35+
notify: reboot containers
36+
37+
- name: Remove lxc cap drop
38+
lineinfile:
39+
dest: "{{ item }}"
40+
regexp: "^lxc.cap.drop"
41+
line: "lxc.cap.drop: "
42+
state: absent
43+
loop: "{{ proxmox_lxc_filtered_files }}"
44+
notify: reboot containers
45+
46+
- name: Remove lxc mounts
47+
lineinfile:
48+
dest: "{{ item }}"
49+
regexp: "^lxc.mount.auto"
50+
line: 'lxc.mount.auto: "proc:rw sys:rw"'
51+
state: absent
52+
loop: "{{ proxmox_lxc_filtered_files }}"
53+
notify: reboot containers

site.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
gather_facts: yes
1313
roles:
1414
- role: lxc
15+
become: true
1516
when: proxmox_lxc_configure
1617
- role: prereq
1718
become: true

scripts/rc.local renamed to templates/rc.local.j2

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/bin/sh -e
2-
31
# Kubeadm 1.15 needs /dev/kmsg to be there, but it's not in lxc, but we can just use /dev/console instead
42
# see: https://github.com/kubernetes-sigs/kind/issues/662
53
if [ ! -e /dev/kmsg ]; then

0 commit comments

Comments
 (0)