finish os stage 3 download extract, configure mount and chroot
This commit is contained in:
parent
3ee290940d
commit
933cd014fa
@ -18,6 +18,13 @@ RUN addgroup -g 1000 "${GROUP}" && \
|
|||||||
echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER && \
|
echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER && \
|
||||||
chmod 0440 /etc/sudoers.d/$USER
|
chmod 0440 /etc/sudoers.d/$USER
|
||||||
|
|
||||||
|
# setup mitogen to enhance ansible speed
|
||||||
|
ENV MITOGEN_VERSION="0.2.9"
|
||||||
|
RUN wget https://networkgenomics.com/try/mitogen-${MITOGEN_VERSION}.tar.gz && \
|
||||||
|
tar xvf mitogen-${MITOGEN_VERSION}.tar.gz && \
|
||||||
|
mv mitogen-${MITOGEN_VERSION} /mitogen && \
|
||||||
|
rm mitogen-${MITOGEN_VERSION}.tar.gz
|
||||||
|
|
||||||
USER "${USER}"
|
USER "${USER}"
|
||||||
|
|
||||||
ENV PACKER_LOG=1
|
ENV PACKER_LOG=1
|
||||||
|
@ -1,2 +1,5 @@
|
|||||||
[defaults]
|
[defaults]
|
||||||
host_key_checking = false
|
host_key_checking = false
|
||||||
|
|
||||||
|
strategy_plugins = /mitogen/ansible_mitogen/plugins/strategy
|
||||||
|
strategy = mitogen_linear
|
@ -1,4 +1,4 @@
|
|||||||
[default]
|
[default]
|
||||||
100.64.0.24 ansible_ssh_pass=toor ansible_ssh_port=5556 ansible_user=root
|
100.64.0.24 ansible_ssh_pass=toor ansible_ssh_port=5556 ansible_user=root debug=true
|
||||||
#192.168.1.24 ansible_ssh_pass=toor ansible_ssh_port=5556 ansible_user=root
|
;192.168.1.24 ansible_ssh_pass=toor ansible_ssh_port=5556 ansible_user=root debug=true
|
||||||
|
;192.168.1.22 ansible_ssh_pass=toor ansible_ssh_port=5556 ansible_user=root debug=true
|
||||||
|
@ -24,7 +24,6 @@ devices_system:
|
|||||||
part_end: 100%
|
part_end: 100%
|
||||||
fstype: "lvm"
|
fstype: "lvm"
|
||||||
|
|
||||||
vg_name: vg_system
|
|
||||||
lvs:
|
lvs:
|
||||||
- name: "swap"
|
- name: "swap"
|
||||||
size: "1G"
|
size: "1G"
|
||||||
@ -34,8 +33,13 @@ lvs:
|
|||||||
size: "22G"
|
size: "22G"
|
||||||
type: "ext4"
|
type: "ext4"
|
||||||
descr: "Root partition"
|
descr: "Root partition"
|
||||||
|
mount_dir: "{{ mount_base_dir }}"
|
||||||
- name: "home"
|
- name: "home"
|
||||||
size: "7G"
|
size: "7G"
|
||||||
type: "ext4"
|
type: "ext4"
|
||||||
descr: "home partition"
|
descr: "home partition"
|
||||||
|
mount_dir: "{{ mount_base_dir }}/home"
|
||||||
|
|
||||||
|
# default swapiness value
|
||||||
|
swapiness: "60"
|
||||||
|
gentoo_version: "lastest"
|
69
packer/assets/ansible/roles/setup/tasks/configure.yml
Normal file
69
packer/assets/ansible/roles/setup/tasks/configure.yml
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
---
|
||||||
|
# configure and setup os
|
||||||
|
|
||||||
|
- name:
|
||||||
|
set_fact:
|
||||||
|
make_conf:
|
||||||
|
- path: "GENTOO_MIRRORS=\"{{ mirror_source }}\""
|
||||||
|
regexp: "^GENTOO_MIRRORS=\".*\""
|
||||||
|
- path: "COMMON_FLAGS=\"{{ gcc_common_args }}\""
|
||||||
|
regexp: "^COMMON_FLAGS="
|
||||||
|
- path: "MAKEOPTS=\"{{ make_opts }}\""
|
||||||
|
regexp: "^MAKEOPTS="
|
||||||
|
tags:
|
||||||
|
- configure
|
||||||
|
|
||||||
|
- name: "Configure Gentoo_mirrors"
|
||||||
|
lineinfile:
|
||||||
|
path: "{{ mount_base_dir }}/etc/portage/make.conf"
|
||||||
|
regexp: "{{ item.regexp }}"
|
||||||
|
line: "{{ item.path }}"
|
||||||
|
state: present
|
||||||
|
loop: "{{ make_conf }}"
|
||||||
|
tags:
|
||||||
|
- configure
|
||||||
|
|
||||||
|
- name: "Create portage repo conf dir"
|
||||||
|
file:
|
||||||
|
path: "{{ portage_conf_dir_path }}"
|
||||||
|
state: directory
|
||||||
|
tags:
|
||||||
|
- configure
|
||||||
|
|
||||||
|
- name: "Copy portage conf file"
|
||||||
|
copy:
|
||||||
|
src: "{{ item.src }}"
|
||||||
|
dest: "{{ item.dest }}"
|
||||||
|
remote_src: yes
|
||||||
|
loop:
|
||||||
|
- src: "{{ mount_base_dir }}/usr/share/portage/config/repos.conf"
|
||||||
|
dest: "{{ portage_conf_dir_path }}/gentoo.conf"
|
||||||
|
- src: "/etc/resolv.conf"
|
||||||
|
dest: "{{ mount_base_dir }}/etc/resolv.conf"
|
||||||
|
tags:
|
||||||
|
- configure
|
||||||
|
|
||||||
|
#- name: create portage directory
|
||||||
|
# command: chroot /mnt/gentoo bash -c 'source /etc/profile; mkdir /usr/portage' creates=/mnt/gentoo/usr/portage
|
||||||
|
# tags:
|
||||||
|
# - chroot
|
||||||
|
#
|
||||||
|
#- name: emerge-webrsync
|
||||||
|
# command: chroot /mnt/gentoo bash -c 'source /etc/profile; /usr/bin/emerge-webrsync' creates=/mnt/gentoo/usr/portage/xfce-extra
|
||||||
|
# tags:
|
||||||
|
# - chroot
|
||||||
|
#
|
||||||
|
#- name: set zoneinfo
|
||||||
|
# command: chroot /mnt/gentoo bash -c 'cp /usr/share/zoneinfo/{{ timezone }} /etc/localtime; echo "{{ timezone }}" > /etc/timezone'
|
||||||
|
# tags:
|
||||||
|
# - chroot
|
||||||
|
#
|
||||||
|
#- name: Configure Hosts File
|
||||||
|
# template: src=hosts dest=/mnt/gentoo/etc/hosts
|
||||||
|
#
|
||||||
|
#- name: Set Hostname
|
||||||
|
# template: src=hostname dest=/mnt/gentoo/etc/conf.d/hostname
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#- name: Configure Fstab
|
||||||
|
# copy: src=fstab dest=/mnt/gentoo/etc/fstab
|
@ -2,6 +2,9 @@
|
|||||||
# setup gentoo
|
# setup gentoo
|
||||||
|
|
||||||
- import_tasks: partition.yml
|
- import_tasks: partition.yml
|
||||||
|
- import_tasks: mount.yml
|
||||||
|
- import_tasks: os.yml
|
||||||
|
- import_tasks: configure.yml
|
||||||
#- import_tasks: users.yml
|
#- import_tasks: users.yml
|
||||||
#- import_tasks: security.yml
|
#- import_tasks: security.yml
|
||||||
|
|
||||||
|
43
packer/assets/ansible/roles/setup/tasks/mount.yml
Normal file
43
packer/assets/ansible/roles/setup/tasks/mount.yml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: "Enable swap partition"
|
||||||
|
command: "swapon /dev/{{ vg_name }}/{{ item.name }}"
|
||||||
|
loop: "{{ lvs }}"
|
||||||
|
when: "'swap' in item.type"
|
||||||
|
tags:
|
||||||
|
- mount
|
||||||
|
|
||||||
|
- name: "Set swappiness value"
|
||||||
|
sysctl:
|
||||||
|
name: vm.swappiness
|
||||||
|
value: "{{ swapiness }}"
|
||||||
|
state: present
|
||||||
|
tags:
|
||||||
|
- mount
|
||||||
|
|
||||||
|
- name: "Create mountpoints base dir"
|
||||||
|
file:
|
||||||
|
path: "{{ mount_base_dir }}"
|
||||||
|
state: directory
|
||||||
|
tags:
|
||||||
|
- mount
|
||||||
|
|
||||||
|
- name: "Create mountpoints"
|
||||||
|
file:
|
||||||
|
path: "{{ item.mount_dir }}"
|
||||||
|
state: directory
|
||||||
|
loop: "{{ lvs }}"
|
||||||
|
when: "item.mount_dir is defined"
|
||||||
|
tags:
|
||||||
|
- mount
|
||||||
|
|
||||||
|
- name: "Mount partition"
|
||||||
|
mount:
|
||||||
|
path: "{{ item.mount_dir }}"
|
||||||
|
src: "/dev/{{ vg_name }}/{{ item.name }}"
|
||||||
|
fstype: "{{ item.type }}"
|
||||||
|
state: mounted
|
||||||
|
loop: "{{ lvs }}"
|
||||||
|
when: "item.mount_dir is defined"
|
||||||
|
tags:
|
||||||
|
- mount
|
70
packer/assets/ansible/roles/setup/tasks/os.yml
Normal file
70
packer/assets/ansible/roles/setup/tasks/os.yml
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
---
|
||||||
|
# retrieve gentoo os and copy it
|
||||||
|
|
||||||
|
- name: "Set time"
|
||||||
|
command: "ntpd -q -g"
|
||||||
|
tags:
|
||||||
|
- os
|
||||||
|
|
||||||
|
- name: "Retrieve last version"
|
||||||
|
shell: >
|
||||||
|
curl {{ latest_url }} 2>&1 |
|
||||||
|
awk -F/ '/\/stage3-amd64-[0-9TZ]+.tar.xz/{print $1}'
|
||||||
|
args:
|
||||||
|
warn: no
|
||||||
|
when: "gentoo_version is not defined or gentoo_version == 'lastest'"
|
||||||
|
register: "stage_path"
|
||||||
|
tags:
|
||||||
|
- os
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
url_dl: "{{ mirror_stage }}/releases/amd64/autobuilds/{{ stage_path.stdout | default(gentoo_version) }}/stage3-amd64-{{ stage_path.stdout | default(gentoo_version) }}.tar.xz"
|
||||||
|
tags:
|
||||||
|
- os
|
||||||
|
|
||||||
|
- name: "Download stage3 archive version {{ stage_path.stdout }}"
|
||||||
|
get_url:
|
||||||
|
url: "{{ url_dl }}"
|
||||||
|
dest: "/root/stage3-amd64.tar.xz"
|
||||||
|
register: "archive_downloaded_result"
|
||||||
|
tags:
|
||||||
|
- os
|
||||||
|
|
||||||
|
- name: "Extract stage3 archive"
|
||||||
|
unarchive:
|
||||||
|
src: "{{ archive_downloaded_result.dest }}"
|
||||||
|
dest: "{{ mount_base_dir }}"
|
||||||
|
remote_src: yes
|
||||||
|
creates: "{{ mount_base_dir }}/bin"
|
||||||
|
tags:
|
||||||
|
- os
|
||||||
|
|
||||||
|
- name: "Mount /proc"
|
||||||
|
mount:
|
||||||
|
src: /proc
|
||||||
|
path: "{{ mount_base_dir }}/proc"
|
||||||
|
state: mounted
|
||||||
|
fstype: proc
|
||||||
|
tags:
|
||||||
|
- os
|
||||||
|
|
||||||
|
- name: "Mount /dev bind volume"
|
||||||
|
mount:
|
||||||
|
src: "/{{ item.path }}"
|
||||||
|
path: "{{ mount_base_dir }}/{{ item.path }}"
|
||||||
|
opts: rbind,make-rslave
|
||||||
|
state: mounted
|
||||||
|
fstype: none
|
||||||
|
loop:
|
||||||
|
- path: dev
|
||||||
|
- path: sys
|
||||||
|
tags:
|
||||||
|
- os
|
||||||
|
|
||||||
|
- name: "Cleanup Stage3 Archive"
|
||||||
|
file:
|
||||||
|
path: "{{ archive_downloaded_result.dest }}"
|
||||||
|
state: absent
|
||||||
|
when: "debug is not defined or debug == false"
|
||||||
|
tags:
|
||||||
|
- os
|
@ -38,6 +38,10 @@
|
|||||||
tags:
|
tags:
|
||||||
- storage
|
- storage
|
||||||
|
|
||||||
|
- import_tasks: "umount.yml"
|
||||||
|
tags:
|
||||||
|
- storage
|
||||||
|
|
||||||
- name: "Create list of lvs"
|
- name: "Create list of lvs"
|
||||||
lvol:
|
lvol:
|
||||||
vg: "{{ vg_name }}"
|
vg: "{{ vg_name }}"
|
||||||
@ -52,7 +56,6 @@
|
|||||||
fstype: "{{ item.type }}"
|
fstype: "{{ item.type }}"
|
||||||
dev: "/dev/{{ vg_name }}/{{ item.name }}"
|
dev: "/dev/{{ vg_name }}/{{ item.name }}"
|
||||||
force: yes
|
force: yes
|
||||||
resizefs: yes
|
|
||||||
loop: "{{ lvs }}"
|
loop: "{{ lvs }}"
|
||||||
tags:
|
tags:
|
||||||
- storage
|
- storage
|
16
packer/assets/ansible/roles/setup/tasks/umount.yml
Normal file
16
packer/assets/ansible/roles/setup/tasks/umount.yml
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
# umount and disabe swap
|
||||||
|
|
||||||
|
- name: "disable swap partition"
|
||||||
|
command: "swapoff -a"
|
||||||
|
tags:
|
||||||
|
- umount
|
||||||
|
|
||||||
|
- name: "Umount partition"
|
||||||
|
mount:
|
||||||
|
path: "{{ item.mount_dir }}"
|
||||||
|
state: "unmounted"
|
||||||
|
loop: "{{ lvs | reverse | list }}"
|
||||||
|
when: "item.mount_dir is defined"
|
||||||
|
tags:
|
||||||
|
- umount
|
22
packer/assets/ansible/roles/setup/vars/main.yml
Normal file
22
packer/assets/ansible/roles/setup/vars/main.yml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
# non overridable variable
|
||||||
|
|
||||||
|
vg_name: vg_system
|
||||||
|
mount_base_dir: /mnt/gentoo
|
||||||
|
mirror_stage: "https://gentoo.osuosl.org"
|
||||||
|
latest_url: "{{ mirror_stage }}/releases/amd64/autobuilds/latest-stage3.txt"
|
||||||
|
|
||||||
|
# compilation arguments
|
||||||
|
mirror_source: >
|
||||||
|
http://gentoo.mirrors.ovh.net/gentoo-distfiles/
|
||||||
|
ftp://ftp.free.fr/mirrors/ftp.gentoo.org/
|
||||||
|
http://ftp.free.fr/mirrors/ftp.gentoo.org/
|
||||||
|
https://mirrors.soeasyto.com/distfiles.gentoo.org/
|
||||||
|
http://mirrors.soeasyto.com/distfiles.gentoo.org/
|
||||||
|
ftp://mirrors.soeasyto.com/distfiles.gentoo.org/
|
||||||
|
http://gentoo.modulix.net/gentoo/
|
||||||
|
gcc_common_args: "-march=native -O2 -pipe"
|
||||||
|
make_opts: "-j2"
|
||||||
|
|
||||||
|
# portage variable
|
||||||
|
portage_conf_dir_path: "{{ mount_base_dir }}/etc/portage/repos.conf/"
|
@ -1,7 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
PLAYBOOK="${1:-playbook.yml}"
|
PLAYBOOK="${1:-playbook.yml}"
|
||||||
DEBUG="-vvv"
|
#DEBUG="-vvv"
|
||||||
|
TAGS="--tags configure"
|
||||||
|
|
||||||
# run playbook on aready running qemu vm
|
# run playbook on aready running qemu vm
|
||||||
ansible-playbook -i inventory_test.ini "$PLAYBOOK" --extra-vars "ssh_pub=$(cat ../id_rsa_qemu) generated_user=antoine generated_group=antoine"
|
ansible-playbook $DEBUG -i inventory_test.ini $TAGS --extra-vars "ssh_pub=$(cat ../id_rsa_qemu) generated_user=antoine generated_group=antoine" $PLAYBOOK
|
||||||
|
@ -83,7 +83,7 @@
|
|||||||
{
|
{
|
||||||
"type": "ansible",
|
"type": "ansible",
|
||||||
"playbook_file": "/packer/ansible/playbook.yml",
|
"playbook_file": "/packer/ansible/playbook.yml",
|
||||||
"extra_arguments": [ "--extra-vars", "ssh_pub={{user `ssh_pub_key`}} generated_user={{user `generated_user`}} generated_group={{user `generated_group`}}" ],
|
"extra_arguments": [ "--extra-vars", "ssh_pub={{user `ssh_pub_key`}} generated_user={{user `generated_user`}} generated_group={{user `generated_group`}} gentoo_version={{user `version`}}" ],
|
||||||
"groups": "default",
|
"groups": "default",
|
||||||
"user": "root",
|
"user": "root",
|
||||||
"ansible_env_vars": [ "ANSIBLE_CONFIG=/packer/ansible/ansible.cfg" ]
|
"ansible_env_vars": [ "ANSIBLE_CONFIG=/packer/ansible/ansible.cfg" ]
|
||||||
|
Loading…
Reference in New Issue
Block a user