Skip to content

Commit a773775

Browse files
committed
builder.yml: Ensure consistent subuid and subgid across builders
This might explain a lot of the storage weirdness we've been observing. If a container image layer is create in rootless on podman on one machine, that image layer is restored to another host with *different* subuid or subgid, errors can occur. Signed-off-by: David Galloway <david.galloway@ibm.com>
1 parent 5ca3aa1 commit a773775

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

ansible/examples/builder.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
libvirt: false # Should vagrant be installed?
5555
permanent: false # Is this a permanent builder? Since the ephemeral (non-permanent) tasks get run more often, we'll default to false.
5656
jenkins_user: 'jenkins-build'
57+
subid_range_size: 65536
58+
subid_uid_start: 1148577
59+
subid_gid_start: 1148577
5760
api_user: 'ceph-jenkins'
5861
api_uri: 'https://jenkins.ceph.com'
5962
jenkins_credentials_uuid: 'jenkins-build'
@@ -673,6 +676,20 @@
673676
- name: "loginctl enable-linger {{ jenkins_user }}"
674677
command: "loginctl enable-linger {{ jenkins_user }}"
675678

679+
- name: Ensure subuid range for {{ jenkins_user }}
680+
ansible.builtin.lineinfile:
681+
path: /etc/subuid
682+
create: true
683+
regexp: "^{{ jenkins_user }}:"
684+
line: "{{ jenkins_user }}:{{ subid_uid_start }}:{{ subid_range_size }}"
685+
686+
- name: Ensure subgid range for {{ jenkins_user }}
687+
ansible.builtin.lineinfile:
688+
path: /etc/subgid
689+
create: true
690+
regexp: "^{{ jenkins_user }}:"
691+
line: "{{ jenkins_user }}:{{ subid_gid_start }}:{{ subid_range_size }}"
692+
676693
- name: "Create a {{ jenkins_user }} home directory"
677694
file:
678695
path: "/home/{{ jenkins_user }}/"
@@ -768,6 +785,34 @@
768785
command: "sudo chown -R {{ jenkins_user }}:{{ jenkins_user }} /home/{{ jenkins_user}}"
769786
tags: chown
770787

788+
- name: Reset rootless podman storage for {{ jenkins_user }} (required after subuid/subgid changes)
789+
block:
790+
- name: Stop and remove any running rootless containers
791+
become: true
792+
become_user: "{{ jenkins_user }}"
793+
command: /bin/sh -lc 'podman ps -aq | xargs -r podman rm -f'
794+
args:
795+
chdir: "/home/{{ jenkins_user }}"
796+
changed_when: false
797+
failed_when: false
798+
799+
- name: Remove rootless podman storage
800+
file:
801+
path: "/home/{{ jenkins_user }}/.local/share/containers/storage"
802+
state: absent
803+
804+
- name: Remove rootless podman cache
805+
file:
806+
path: "/home/{{ jenkins_user }}/.local/share/containers/cache"
807+
state: absent
808+
809+
- name: Restore SELinux labels on containers directory (if applicable)
810+
command: >
811+
restorecon -R -T0 -x /home/{{ jenkins_user }}/.local/share/containers
812+
when: ansible_selinux.status == "enabled"
813+
tags:
814+
- podman-reset
815+
771816
## DEBIAN GPG KEY TASKS
772817
- name: Install Debian GPG Keys on Ubuntu
773818
block:

0 commit comments

Comments
 (0)