Skip to content

Commit

Permalink
[Feature/packer/template] Add Ubuntu 2204-1 VM Template Support (#170)
Browse files Browse the repository at this point in the history
* patch(roles/minio.ops): refine logics for setup.ops

* feat(backery/template): added ubuntu-2204-1 vm template support

* patch(custom.packer.hcl): unset key encryption for minio role

patch(packer/template/custom): comment out encryption key upload - optional feature
  • Loading branch information
piyoki committed Aug 27, 2022
1 parent 9fb17c5 commit bd34896
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 32 deletions.
14 changes: 12 additions & 2 deletions packer-templates/bakery-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
"iso": "ubuntu-22.04-live-server-amd64.iso",
"playbook": "ubuntu-2204-server.yml"
},
"ubuntu-2204-1-server": {
"image_name": "ubuntu-2204-1-server",
"iso": "ubuntu-22.04.1-live-server-amd64.iso",
"playbook": "ubuntu-2204-1-server.yml"
},
"docker-ubuntu-2204-server": {
"image_name": "docker-ubuntu-2204-server",
"iso": "ubuntu-22.04-live-server-amd64.iso",
Expand All @@ -24,9 +29,14 @@
"iso": "ubuntu-22.04-live-server-amd64.iso",
"playbook": "cn-ubuntu-2204-server.yml"
},
"cn-ubuntu-2204-1-server": {
"image_name": "cn-ubuntu-2204-1-server",
"iso": "ubuntu-22.04.1-live-server-amd64.iso",
"playbook": "cn-ubuntu-2204-1-server.yml"
},
"custom": {
"image_name": "cn-ubuntu-2204-server",
"iso": "ubuntu-22.04-live-server-amd64.iso",
"image_name": "custom-server",
"iso": "ubuntu-22.04.1-live-server-amd64.iso",
"playbook": "custom.yml"
}
}
14 changes: 8 additions & 6 deletions packer-templates/custom-proxmox-packer-template.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,19 @@ build {
}

# Minio plabyook
provisioner "file" {
pause_before = "5s"
source = "./playbooks/.vault_pass"
destination = "/tmp/.vault_pass"
}

# provisioner "file" { # key-encryption is an optional feature
# pause_before = "5s"
# source = "./playbooks/.vault_pass"
# destination = "/tmp/.vault_pass"
# }

provisioner "ansible-local" {
playbook_dir = "./playbooks"
playbook_file = "./playbooks/minio.yml"
clean_staging_directory = true
extra_arguments = [
"--vault-password-file=/tmp/.vault_pass",
# "--vault-password-file=/tmp/.vault_pass",
"--extra-vars \"ansible_user=packer\""
]
}
Expand Down
23 changes: 23 additions & 0 deletions packer-templates/playbooks/cn-ubuntu-2204-1-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
# Bake cn-ubuntu-2204-server

- name: "Bake proxmox cn ubuntu 22.04.1 server"
hosts: localhost
become: yes

vars_files:
- ./vars/apt.yml
- ./vars/maintenance.yml

roles:
- role: ./roles/apt.ops/set-sources.ops/
vars:
release: "jammy"
- role: ./roles/apt.ops/install-packages.ops/
vars:
extra_packages:
- neofetch

- role: ./roles/maintenance.ops/key.ops/

- role: ./roles/proxmox.bootstrap/
2 changes: 1 addition & 1 deletion packer-templates/playbooks/cn-ubuntu-2204-server.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# Bake cn-ubuntu-2204-server

- name: "Bake proxmox cn ubuntu 2204 server"
- name: "Bake proxmox cn ubuntu 22.04 server"
hosts: localhost
become: yes

Expand Down
20 changes: 3 additions & 17 deletions packer-templates/playbooks/minio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,8 @@
hosts: localhost
become: yes

vars_files:
- ./vars/minio.yml

roles:
- role: ./roles/minio.ops/
vars:
remote_server: "http://10.178.0.9:9000"
minio_access_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
34363862333037363538373034323437326432343332303338636666656131653437613432316461
3034643833316266396366626364616330343363303464370a326235636139396263626331343533
34366239376137333537653331313132663434616139616463356138373064373038366165633537
3438343265393233360a643263656633633731633965316363333363306264646663333137663761
61373864333534376163666165383861366231636637633731356364336533646333
minio_secret_key: !vault |
$ANSIBLE_VAULT;1.1;AES256
63353731353333646530393635656233343833383237346431356431316561666537343061623231
6238643636343734313735333537616438633430316132300a326562646361666635363735336362
34623863326635306361623864393461313161343330376265336365373335376432353361363234
6138366435643439340a383262303333626431343430313262636464636137363034623337656562
32323066346435656230356466623333336530633435653536643263653532646137663665316536
3964353138323330353934383436323132623435356135653139
38 changes: 35 additions & 3 deletions packer-templates/playbooks/roles/minio.ops/tasks/setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,39 @@
- name: Enable autocompletion
shell: "mc --autocompletion >/dev/null 2>&1"

- name: Connect to remote minio server with credentials
command: "mc config host add minio {{ remote_server }} {{ minio_access_key }} {{ minio_secret_key }}"
become: yes
- name: Configure minio
become_user: "{{ ansible_user }}"
block:
- name: Create minio default directory
file:
path: /home/{{ ansible_user }}/.mc
state: directory
owner: "{{ ansible_user }}"
group: users
mode: 0755

- name: Create minio default directory (root)
become_user: root
file:
path: /root/.mc
state: directory
owner: root
group: root
mode: 0755

- name: Copy minio config file to remote server
ansible.builtin.template:
src: config.json.j2
dest: /home/{{ ansible_user }}/.mc/config.json
owner: "{{ ansible_user }}"
group: users
mode: 0644

- name: Copy minio config file to remote server
become_user: root
ansible.builtin.template:
src: config.json.j2
dest: /root/.mc/config.json
owner: root
group: root
mode: 0644
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "10",
"aliases": {
"minio": {
"url": "{{ minio_remote_url }}",
"accessKey": "{{ minio_access_key }}",
"secretKey": "{{ minio_secret_key }}",
"api": "s3v4",
"path": "auto"
}
}
}
2 changes: 1 addition & 1 deletion packer-templates/playbooks/ubuntu-2004-server.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# Bake ubuntu-2004-server

- name: "Bake proxmox ubuntu 2004 server"
- name: "Bake proxmox ubuntu 20.04 server"
hosts: localhost
become: yes

Expand Down
21 changes: 21 additions & 0 deletions packer-templates/playbooks/ubuntu-2204-1-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# Bake ubuntu-2204-server

- name: "Bake proxmox ubuntu 22.04.1 server"
hosts: localhost
become: yes

vars_files:
- ./vars/apt.yml
- ./vars/maintenance.yml

roles:
- role: ./roles/apt.ops/update.ops/
- role: ./roles/apt.ops/install-packages.ops/
vars:
extra_packages:
- neofetch

- role: ./roles/maintenance.ops/key.ops/

- role: ./roles/proxmox.bootstrap/
2 changes: 1 addition & 1 deletion packer-templates/playbooks/ubuntu-2204-server.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# Bake ubuntu-2204-server

- name: "Bake proxmox ubuntu 2204 server"
- name: "Bake proxmox ubuntu 22.04 server"
hosts: localhost
become: yes

Expand Down
2 changes: 1 addition & 1 deletion packer-templates/playbooks/vars/minio.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
# ../../roles/minio.ops/
remote_server: "http://10.178.0.9:9000"
minio_remote_url: "http://10.178.0.9:9000"
minio_access_key: "{{ lookup('env','MINIO_ACCESS_KEY')}}"
minio_secret_key: "{{ lookup('env','MINIO_SECRET_KEY')}}"
44 changes: 44 additions & 0 deletions packer-templates/vars/kevin-ubuntu-2204-1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"os": "l26",
"cores": "20",
"sockets": "1",
"memory": "2048",
"bridge": "vmbr2",
"disk_type": "scsi",
"disk_size": "10G",
"disk_format": "raw",
"disk_cache_mode": "writeback",
"datastore": "sata-pool",
"datastore_type": "directory",
"cloud_init_storage_pool": "sata-pool",

"iso": "sata-pool:iso/ubuntu-22.04.1-live-server-amd64.iso",

"ssh_password": "packer",
"ssh_username": "packer",
"ssh_timeout": "60m",

"http_directory": "http",

"boot_command": [
"<esc><esc><esc><esc>e<wait>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"<del><del><del><del><del><del><del><del>",
"linux /casper/vmlinuz --- autoinstall ds=\"nocloud-net;seedfrom=http://{{.HTTPIP}}:{{.HTTPPort}}/\"<enter><wait>",
"initrd /casper/initrd<enter><wait>",
"boot<enter>",
"<enter><f10><wait>"
]
}

0 comments on commit bd34896

Please sign in to comment.