Skip to content

Commit a0b3dc4

Browse files
committed
move image finalisation into role
1 parent 5835cd2 commit a0b3dc4

File tree

4 files changed

+82
-2
lines changed

4 files changed

+82
-2
lines changed

ansible/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,5 @@ roles/*
6060
!roles/tuned/**
6161
!roles/lustre/
6262
!roles/lustre/**
63+
!roles/builder/
64+
!roles/builder/**

ansible/fatimage.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@
207207
gather_facts: yes
208208
tags: finalise
209209
tasks:
210-
- name: Cleanup image
211-
import_tasks: cleanup.yml
210+
- name: Finalise image
211+
import_role:
212+
name: builder
213+
tasks_from: finalise.yml
212214

213215
- name: Shutdown Packer VM
214216
community.general.shutdown:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
builder_delete_syslog: true
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Finalise a Packer build VM
2+
3+
- meta: flush_handlers
4+
5+
- name: Remove dnf caches
6+
command: dnf clean all
7+
8+
# If image build happens on a Neutron subnet with property dns_namservers defined, then cloud-init
9+
# disables NetworkManager's control of /etc/resolv.conf and appends nameservers itself.
10+
# We don't want network configuration during instance boot to depend on the configuration
11+
# of the network the builder was on, so we reset these aspects.
12+
- name: Delete /etc/resolv.conf
13+
file:
14+
path: /etc/resolv.conf
15+
state: absent
16+
when: "'resolv_conf' not in group_names" # if its been overriden, deleting it is the wrong thing to do
17+
18+
- name: Reenable NetworkManager control of resolv.conf
19+
# NB: This *doesn't* delete the 90-dns-none.conf file created by the resolv_conf role
20+
# as if nameservers are explicitly being set by that role we don't want to allow NM
21+
# to override it again.
22+
file:
23+
path: /etc/NetworkManager/conf.d/99-cloud-init.conf
24+
state: absent
25+
26+
- name: Get remote environment for ansible_user
27+
setup:
28+
gather_subset: env
29+
become: no
30+
31+
- name: Delete any injected ssh config for ansible_user
32+
file:
33+
path: "{{ ansible_env.HOME }}/.ssh/"
34+
state: absent
35+
36+
- name: Run cloud-init cleanup
37+
command: cloud-init clean --logs --seed
38+
39+
- name: Cleanup /tmp
40+
command : rm -rf /tmp/*
41+
42+
- name: Get package facts
43+
package_facts:
44+
45+
- name: Ensure image summary directory exists
46+
file:
47+
path: /var/lib/image/
48+
state: directory
49+
owner: root
50+
group: root
51+
mode: u=rwX,go=rX
52+
53+
- name: Write image summary
54+
copy:
55+
content: "{{ image_info | to_nice_json }}"
56+
dest: /var/lib/image/image.json
57+
vars:
58+
image_info:
59+
branch: "{{ lookup('pipe', 'git rev-parse --abbrev-ref HEAD') }}"
60+
build: "{{ ansible_nodename | split('.') | first }}" # hostname is image name, which contains build info
61+
os: "{{ ansible_distribution }} {{ ansible_distribution_version }}"
62+
kernel: "{{ ansible_kernel }}"
63+
ofed: "{{ ansible_facts.packages['mlnx-ofa_kernel'].0.version | default('-') }}"
64+
cuda: "{{ ansible_facts.packages['cuda'].0.version | default('-') }}"
65+
slurm-ohpc: "{{ ansible_facts.packages['slurm-ohpc'].0.version | default('-') }}"
66+
ondemand: "{{ ansible_facts.packages['ondemand'].0.version | default('-') }}"
67+
68+
- name: Clear system logs
69+
file:
70+
path: /var/log/messages
71+
state: absent
72+
when: "{{ builder_delete_syslog | bool }}"
73+
74+
- name: Shutdown Packer VM
75+
community.general.shutdown:

0 commit comments

Comments
 (0)