finish partitionning

This commit is contained in:
Antoine 2020-03-03 23:20:24 +01:00
parent 2b1a9b7214
commit 3ee290940d
13 changed files with 117 additions and 40 deletions

3
.gitignore vendored
View File

@ -9,3 +9,6 @@
packer/assets/id_rsa_qemu*
packer/assets/packer_cache/
packer/assets/output_gentoo_qcow2/
.idea/
*.iml

View File

@ -5,3 +5,7 @@ Run packer into docker container with qemu to build qcow2 gentoo os
## use
run `make up` to start container and build qcow2
## iso checksum
`iso_checksum_url": "http://distfiles.gentoo.org/releases/amd64/autobuilds/current-install-amd64-minimal/install-amd64-minimal-{{user `version`}}.iso.DIGESTS`

View File

@ -11,7 +11,7 @@ WORKDIR /packer
RUN apk add --update qemu qemu-system-x86_64 qemu-img \
vim htop util-linux gzip sysfsutils openssh-client \
openssh-keygen sudo ansible sshpass
openssh-keygen sudo ansible sshpass curl
RUN addgroup -g 1000 "${GROUP}" && \
adduser -u 1000 -D -G "${GROUP}" "${USER}" && \

View File

@ -0,0 +1,2 @@
[defaults]
host_key_checking = false

View File

@ -1,3 +1,4 @@
[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
#192.168.1.24 ansible_ssh_pass=toor ansible_ssh_port=5556 ansible_user=root

View File

@ -0,0 +1,32 @@
---
- hosts: localhost
vars:
my_loop: >
[
{% for i in range(1, 2) %}
{
'name':'prefix-{{ i }}'
}
{% if not loop.last %},{% endif %}
{% endfor %}
]
ips_str: |
{% for idx in range(0,2) %}
- name: 192.168.100.{{ idx }}
test: {{ idx }}
{% endfor %}
ips: "{{ ips_str | from_yaml }}"
tasks:
- debug:
msg: "{{ my_loop }}"
- debug:
msg: "{{ item.name }}"
loop: "{{ my_loop }}"
- debug:
msg: "{{ ips }}"
- debug:
msg: "{{ item.name }}"
loop: "{{ ips }}"

View File

@ -3,7 +3,6 @@
- hosts: default
become: true
become_method: su
pre_tasks:
- name: "check ansible required param"
assert:

View File

@ -2,18 +2,30 @@
# default variable relative to paritionning
devices_path: /dev/sda
devices_system:
- name: root
devices_system:
- name: bootloader
dev: /dev/sda1
label: gpt
flags: [ bios_grub ]
part_start: 0%
part_end: 2MiB
- name: boot
dev: /dev/sda2
label: gpt
flags: [ boot, esp ]
part_start: 2MiB
part_end: 128MiB
fstype: "ext2"
- name: root
dev: /dev/sda3
label: gpt
flags: [ lvm ]
part_start: 128MiB
part_end: 100%
fstype: "lvm"
vg_name: vg_system
lvs:
- name: "bios"
size: "2M"
type: "bootloader"
descr: "BIOS boot partition"
- name: "boot"
size: "128M"
type: "ext2"
descr: "Boot/EFI system partition"
- name: "swap"
size: "1G"
type: "swap"

View File

@ -1,36 +1,58 @@
---
# partition disk to install gentoo
- name: "Create a new primary partition for LVM"
- name: "Create bios, boot and LVM partition"
parted:
device: "{{ devices_path }}"
name: "{{ item.name }}"
label: gpt
number: "{{ ansible_loop.index }}"
flags: [ lvm ]
label: "{{ item.label }}"
flags: "{{ item.flags }}"
part_start: "{{ item.part_start }}"
part_end: "{{ item.part_end }}"
state: present
part_end: "100%"
loop: "{{ devices_system }}"
loop_control:
extended: yes
tags:
- storage
- name: "Format partition with fstype keyword"
filesystem:
dev: "{{ item.dev }}"
fstype: "{{ item.fstype }}"
force: yes
resizefs: yes
loop: "{{ devices_system }}"
when: "item.fstype is defined"
tags:
- storage
- name: "Create vg and add disk to it"
lvg:
vg: vg_system
pvs: "{{ devices_system | map(attribute='dev') | join(',') }}"
pvs: "{{ item.dev }}"
force: yes
loop: "{{ devices_system }}"
when: "'lvm' in item.flags"
tags:
- storage
- name: "Create list of lvs"
lvol:
vg: "vg_system"
lv: "{{ item.name }}"
size: "{{ item.size }}"
vg: "{{ vg_name }}"
lv: "{{ item.name }}"
size: "{{ item.size }}"
loop: "{{ lvs }}"
tags:
- storage
- name: "Format lvs partition"
filesystem:
fstype: "{{ item.type }}"
dev: "/dev/{{ vg_name }}/{{ item.name }}"
force: yes
resizefs: yes
loop: "{{ lvs }}"
tags:
- storage

View File

@ -1,5 +1,7 @@
#!/bin/bash
# run playbook on aready running qemu vm
ansible-playbook -i inventory_test.ini playbook.yml --extra-vars "ssh_pub=$(cat ../id_rsa_qemu) generated_user=antoine generated_group=antoine"
PLAYBOOK="${1:-playbook.yml}"
DEBUG="-vvv"
# 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"

View File

@ -22,12 +22,11 @@
"disk_additional_size": [],
"iso_urls": [
"/packer/install-amd64-minimal-{{user `version`}}.iso",
"http://distfiles.gentoo.org/releases/amd64/autobuilds/{{user `version`}}/install-amd64-minimal-{{user `version`}}.iso"
"/packer/install-amd64-minimal-20200205T214502Z.iso",
"http://distfiles.gentoo.org/releases/amd64/autobuilds/current-install-amd64-minimal//install-amd64-minimal-{{user `version`}}.iso"
],
"iso_checksum_url": "http://distfiles.gentoo.org/releases/amd64/autobuilds/{{user `version`}}/install-amd64-minimal-{{user `version`}}.iso.DIGESTS.asc",
"iso_checksum_type": "file",
"iso_checksum_url": "/packer/install-amd64-minimal-20200205T214502Z.iso.DIGESTS",
"vm_name": "gentoo_packer.qcow2",
"output_directory": "output_gentoo_qcow2",
@ -87,7 +86,7 @@
"extra_arguments": [ "--extra-vars", "ssh_pub={{user `ssh_pub_key`}} generated_user={{user `generated_user`}} generated_group={{user `generated_group`}}" ],
"groups": "default",
"user": "root",
"ansible_env_vars": [ "ANSIBLE_HOST_KEY_CHECKING=False" ]
"ansible_env_vars": [ "ANSIBLE_CONFIG=/packer/ansible/ansible.cfg" ]
}
],
"variables": {

View File

@ -0,0 +1,2 @@
9bea61ff620257c3343eb3c588c555800488ace01602b7a0e4f89d09a3f976851a81b6501d79cb3696696675b4724c9da82913e4a036f7874a55bfe2b91ee994 install-amd64-minimal-20200205T214502Z.iso

View File

@ -1,12 +1,11 @@
#!/bin/bash
#packer build --only=qemu --var outfile=boxen/gentoo-minimal-hyperv.box --var headless=true --var hyperv_switchname=Ethernet gentoo-minimal.json
latest=$(curl -s http://distfiles.gentoo.org/releases/amd64/autobuilds/latest-install-amd64-minimal.txt \
| grep "^[^#;]" | awk '{print $1}' | cut -d'/' -f1)
SSH_PUB=$(cat ./id_rsa_qemu.pub)
export PACKER_LOG=1; packer build --only=qemu \
-var version="20200205T214502Z" \
-var version="$latest" \
-var ssh_username="root" \
-var ssh_password="toor" \
-var ssh_pub_key="$SSH_PUB" \