-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.yml
More file actions
126 lines (104 loc) · 3.54 KB
/
setup.yml
File metadata and controls
126 lines (104 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
- name: Setup a debian chroot environment for building packages.
hosts: localhost
connection: local
gather_facts: false
become: false
vars_files:
- vars/install_vars.yml
tasks:
- name: "Check local debootstrap installation"
block:
- name: "Check for path `debootstrap_root`"
ansible.builtin.stat:
path: "{{ debootstrap_root }}"
register: st
- name: "Failed Check for path `debootstrap_root`"
ansible.builtin.fail:
msg: "{{ debootstrap_root }} doesn't exists or is not accessible"
when: not (st.stat.isdir)
- name: "Check for executeable `/usr/sbin/debootstrap`"
ansible.builtin.stat:
path: "{{ debootstrap_root }}/usr/sbin/debootstrap"
register: st
- name: Debug stage
ansible.builtin.debug:
var: st
- name: "Failed Check for executable `/usr/sbin/debootstrap`"
ansible.builtin.fail:
msg: "{{ debootstrap_root }} doesn't exists or is not accessible"
when: not (st.stat.exists) and not (st.stat.executable)
- name: "Create Sysroot {{ sysroot }}"
ansible.builtin.file:
path: "{{ sysroot }}"
state: directory
mode: '0755'
recurse: false # Should be that way.
register: create_sysroot
- name: "Verify Empty Sysroot {{ sysroot }}"
ansible.builtin.command: ls -A "{{ sysroot }}"
register: empty_sysroot
when: not (create_sysroot.changed)
- name: "Run debootstrap on path {{ sysroot }}"
ansible.builtin.command:
"{{ debootstrap_root }}/usr/sbin/debootstrap --arch {{ base_debian.arch }} {{ base_debian.suite }} {{ sysroot }}"
become: true
environment:
DEBOOTSTRAP_DIR: "{{ debootstrap_root }}/usr/share/debootstrap"
when: create_sysroot.changed or empty_sysroot.stdout == ""
- name: "Create debchroot skript"
ansible.builtin.copy:
dest: "{{ playbook_dir }}/debchroot"
mode: 0755
content: |
#!/bin/bash
UNDO_TASKS=( )
traphandler() {
local task; local cmd;
for task in "${UNDO_TASKS[@]}"; do
cmd="${task%%:*}"
case "$cmd" in
"umount")
umount "${task#*:}"
;;
*)
;;
esac
done
exit
}
trap traphandler EXIT
set -e
mount -t proc proc "$1/proc"
UNDO_TASKS=( "umount:$1/proc" "${UNDO_TASKS[@]}" )
mount -t sysfs sysfs "$1/sys"
UNDO_TASKS=( "umount:$1/sys" "${UNDO_TASKS[@]}" )
mount -t tmpfs efivars "$1/sys/firmware/efi/efivars"
UNDO_TASKS=( "umount:$1/sys/firmware/efi/efivars" "${UNDO_TASKS[@]}" )
mount -t tmpfs tmpfs "$1/tmp"
UNDO_TASKS=( "umount:$1/tmp" "${UNDO_TASKS[@]}" )
chroot "$@"
- name: Build dynamic chroot inventory
ansible.builtin.add_host:
name: chroot_deb
ansible_host: "{{ sysroot }}"
ansible_connection: community.general.chroot
ansible_chroot_exe: "{{ playbook_dir }}/debchroot"
- name: "Basic setup in chroot"
hosts: chroot_deb
gather_facts: false
vars_files:
- vars/install_vars.yml
tasks:
- name: "Install python3"
ansible.builtin.raw: "apt update && apt -y install python3 python3-apt"
- name: "Install build-essential"
ansible.builtin.apt:
name:
- build-essential
- fakeroot
- devscripts
- name: "Test"
ansible.builtin.blockinfile:
path: /etc/apt/sources.list
block: "deb-src http://deb.debian.org/debian {{ base_debian.suite }} main"